Added computed field has_catch_weight to stock.picking model in product_catch_weight module.

Additionally, added filter and group by for `has_catch_weight` to stock.picking search view.
This commit is contained in:
Kristen Marie Kulha
2018-09-14 11:05:35 -07:00
parent a2f0825ecf
commit 9b47764bbd
3 changed files with 32 additions and 12 deletions

View File

@@ -27,8 +27,12 @@ class AccountInvoiceLine(models.Model):
move_lines = self.purchase_line_id.mapped('move_ids.move_line_ids')
for move_line in move_lines:
qty_done = move_line.qty_done
current_qty_done = qty_done + qty_done_total
r = move_line.lot_id.catch_weight_ratio
ratio = ((ratio * qty_done_total) + (qty_done * r)) / (qty_done + qty_done_total)
if current_qty_done == 0:
ratio = 0
else:
ratio = ((ratio * qty_done_total) + (qty_done * r)) / current_qty_done
qty_done_total += qty_done
catch_weight += move_line.lot_id.catch_weight
price = price * ratio

View File

@@ -8,7 +8,6 @@ class StockProductionLot(models.Model):
catch_weight = fields.Float(string='Catch Weight', digits=(10, 4))
catch_weight_uom_id = fields.Many2one('product.uom', related='product_id.catch_weight_uom_id')
@api.depends('catch_weight')
def _compute_catch_weight_ratio(self):
for lot in self:
@@ -44,3 +43,14 @@ class StockMoveLine(models.Model):
catch_weight_uom_id = fields.Many2one('product.uom', string='Catch Weight UOM')
lot_catch_weight = fields.Float(related='lot_id.catch_weight')
lot_catch_weight_uom_id = fields.Many2one('product.uom', related='product_id.catch_weight_uom_id')
class StockPicking(models.Model):
_inherit = 'stock.picking'
has_catch_weight = fields.Boolean(string="Has Catch Weight", compute='_compute_has_catch_weight', store=True)
@api.depends('move_lines.product_catch_weight_uom_id')
def _compute_has_catch_weight(self):
for picking in self:
picking.has_catch_weight = any(picking.mapped('move_lines.product_catch_weight_uom_id'))

View File

@@ -13,16 +13,6 @@
</field>
</record>
<!--<record id="view_move_line_form_inherit" model="ir.ui.view">-->
<!--<field name="name">stock.move.line.form.inherit</field>-->
<!--<field name="model">stock.move.line</field>-->
<!--<field name="inherit_id" ref="stock.view_move_line_form" />-->
<!--<field name="arch" type="xml">-->
<!--<xpath expr="//field[@name='lot_name']" position="after">-->
<!--<field name="lot_catch_weight_ratio" readonly="1"/>-->
<!--</xpath>-->
<!--</field>-->
<!--</record>-->
<record id="view_stock_move_operations_inherit" model="ir.ui.view">
<field name="name">stock.move.operations.form.inherit</field>
<field name="model">stock.move</field>
@@ -36,6 +26,7 @@
</xpath>
</field>
</record>
<record id="view_stock_move_line_operation_tree_inherit" model="ir.ui.view">
<field name="name">stock.move.line.operations.tree.inherit</field>
<field name="model">stock.move.line</field>
@@ -49,6 +40,7 @@
</xpath>
</field>
</record>
<record id="product_template_form_view_inherit" model="ir.ui.view">
<field name="name">product.template.common.form.inherit</field>
<field name="model">product.template</field>
@@ -59,4 +51,18 @@
</xpath>
</field>
</record>
<record id="stock_view_picking_internal_search_inherit" model="ir.ui.view">
<field name="name">stock.view.picking.internal.search.inherit</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_internal_search" />
<field name="arch" type="xml">
<xpath expr="//filter[@name='done']" position="after">
<filter name="has_catch_weight" string="Has Catch Weight" domain="[('has_catch_weight','=',True)]" help="Pickings with Catch Weight"/>
</xpath>
<xpath expr="//group/filter[@name='picking_type']" position="after">
<filter string="Has Catch Weight" domain="[]" context="{'group_by':'has_catch_weight'}"/>
</xpath>
</field>
</record>
</odoo>