[add] added open packages to product view

This commit is contained in:
Niels Göttsch 2024-07-21 01:59:10 +02:00
parent 46bf4d5c1a
commit 2c97b8a6b1
5 changed files with 26 additions and 5 deletions

View file

@ -9,8 +9,13 @@ class SaleOrderBatchProduct(models.Model):
@api.depends("sale_order_line_ids.product_uom_qty") @api.depends("sale_order_line_ids.product_uom_qty")
def _compute_open_packagin_qty(self): def _compute_open_packagin_qty(self):
for product in self: for product in self:
open_packaging_qty = product.product_packaging_qty - (
sum(product.sale_order_line_ids.mapped("product_uom_qty"))
% product.product_packaging_qty
% product.product_packaging_qty
)
product.open_packaging_qty = ( product.open_packaging_qty = (
sum(product.sale_order_line_ids.mapped("product_uom_qty")) % product.product_packaging_qty 0 if open_packaging_qty == product.product_packaging_qty else open_packaging_qty
) )
@api.model_create_multi @api.model_create_multi

View file

@ -8,6 +8,13 @@
<xpath expr="//field[@name='batch_id']" position="after"> <xpath expr="//field[@name='batch_id']" position="after">
<field name="open_packaging_qty" decoration-warning="(open_packaging_qty != 0)"/> <field name="open_packaging_qty" decoration-warning="(open_packaging_qty != 0)"/>
</xpath> </xpath>
<xpath
expr="//field[@name='sale_order_line_ids']/tree/field[@name='product_uom_qty']"
position="after"
>
<field name="product_uom_ordered_qty" optional="hide"/>
<field name="product_uom_max_qty"/>
</xpath>
</field> </field>
</record> </record>
</odoo> </odoo>

View file

@ -12,6 +12,15 @@
<field name="product_uom_ordered_qty" optional="hide"/> <field name="product_uom_ordered_qty" optional="hide"/>
<field name="product_uom_max_qty"/> <field name="product_uom_max_qty"/>
</xpath> </xpath>
<xpath expr="//field[@name='product_ids']/tree" position="inside">
<field name="open_packaging_qty" invisiable="True"/>
</xpath>
<xpath
expr="//field[@name='product_ids']/tree/field[@name='product_template_id']"
position="attributes"
>
<attribute name="decoration-warning">(open_packaging_qty != 0)</attribute>
</xpath>
</field> </field>
</record> </record>
</odoo> </odoo>

View file

@ -22,7 +22,9 @@ class SaleOrderBatchProduct(models.Model):
product_template_id = fields.Many2one( product_template_id = fields.Many2one(
"product.template", related="product_id.product_tmpl_id", string="Product Template" "product.template", related="product_id.product_tmpl_id", string="Product Template"
) )
sale_order_line_ids = fields.Many2many("sale.order.line", compute="_compute_sale_order_line_ids", store=True) sale_order_line_ids = fields.Many2many(
"sale.order.line", compute="_compute_sale_order_line_ids", store=True, readonly=False
)
product_uom_category_id = fields.Many2one(related="product_id.uom_id.category_id", depends=["product_id"]) product_uom_category_id = fields.Many2one(related="product_id.uom_id.category_id", depends=["product_id"])
product_uom_qty = fields.Float(compute="_compute_uom_qty") product_uom_qty = fields.Float(compute="_compute_uom_qty")
product_uom = fields.Many2one(related="product_id.uom_id") product_uom = fields.Many2one(related="product_id.uom_id")

View file

@ -23,11 +23,9 @@
<notebook> <notebook>
<page string="Sale Order Lines" name="order_line"> <page string="Sale Order Lines" name="order_line">
<field name="sale_order_line_ids" widget="section_and_note_one2many"> <field name="sale_order_line_ids" widget="section_and_note_one2many">
<tree editable="bottom"> <tree editable="bottom" create="0">
<field name="sequence" widget="handle"/> <field name="sequence" widget="handle"/>
<field name="order_partner_id"/> <field name="order_partner_id"/>
<field name="product_template_id"/>
<field name="name"/>
<field name="product_uom_qty"/> <field name="product_uom_qty"/>
<field name="price_unit"/> <field name="price_unit"/>
<field name="price_subtotal"/> <field name="price_subtotal"/>