Improve UI, allowing user to measure the catch weight in a specific unit of measure.

This UOM should be convertable (in the same category) as the normal stock UOM for the product.
Example: If you want to sell 'units' of 50lbs then you should make a "50lbs" UOM in the Weight category and use that as the sale and purchase UOM, then your "Catch Weight UOM" can be the stock "lb(s)" UOM.
This commit is contained in:
Jared Kipe
2018-06-10 11:02:27 -07:00
parent 46d002ddc9
commit b7319f826f
9 changed files with 182 additions and 38 deletions

View File

@@ -1,3 +1,4 @@
from . import account_invoice
from . import product
from . import stock_patch
from . import stock

View File

@@ -7,6 +7,9 @@ _logger = logging.getLogger(__name__)
class AccountInvoiceLine(models.Model):
_inherit = 'account.invoice.line'
catch_weight = fields.Float(string='Catch Weight', digits=(10, 4), compute='_compute_price', store=True)
catch_weight_uom_id = fields.Many2one('product.uom', related='product_id.catch_weight_uom_id')
@api.one
@api.depends('price_unit', 'discount', 'invoice_line_tax_ids', 'quantity',
'product_id', 'invoice_id.partner_id', 'invoice_id.currency_id', 'invoice_id.company_id',
@@ -17,6 +20,7 @@ class AccountInvoiceLine(models.Model):
ratio = 1.0
qty_done_total = 0.0
catch_weight = 0.0
if self.invoice_id.type in ('out_invoice', 'out_refund'):
move_lines = self.sale_line_ids.mapped('move_ids.move_line_ids')
else:
@@ -26,7 +30,9 @@ class AccountInvoiceLine(models.Model):
r = move_line.lot_id.catch_weight_ratio
ratio = ((ratio * qty_done_total) + (qty_done * r)) / (qty_done + qty_done_total)
qty_done_total += qty_done
catch_weight += move_line.lot_id.catch_weight
price = price * ratio
self.catch_weight = catch_weight
taxes = False
if self.invoice_line_tax_ids:

View File

@@ -0,0 +1,7 @@
from odoo import api, fields, models
class ProductProduct(models.Model):
_inherit = 'product.template'
catch_weight_uom_id = fields.Many2one('product.uom', string='Catch Weight UOM')

View File

@@ -4,17 +4,43 @@ from odoo import api, fields, models
class StockProductionLot(models.Model):
_inherit = 'stock.production.lot'
catch_weight_ratio = fields.Float(string='Catch Weight Ratio', digits=(10, 6), default=1.0)
catch_weight_ratio = fields.Float(string='Catch Weight Ratio', digits=(10, 6), compute='_compute_catch_weight_ratio')
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:
if not lot.catch_weight_uom_id:
lot.catch_weight_ratio = 1.0
else:
lot.catch_weight_ratio = lot.catch_weight_uom_id._compute_quantity(lot.catch_weight,
lot.product_id.uom_id,
rounding_method='DOWN')
class StockMove(models.Model):
_inherit = 'stock.move'
product_catch_weight_uom_id = fields.Many2one('product.uom', related="product_id.catch_weight_uom_id")
def _prepare_move_line_vals(self, quantity=None, reserved_quant=None):
vals = super(StockMove, self)._prepare_move_line_vals(quantity=quantity, reserved_quant=reserved_quant)
vals['catch_weight_uom_id'] = self.product_catch_weight_uom_id.id if self.product_catch_weight_uom_id else False
return vals
def action_show_details(self):
action = super(StockMove, self).action_show_details()
action['context']['show_catch_weight'] = bool(self.product_id.catch_weight_uom_id)
return action
class StockMoveLine(models.Model):
_inherit = 'stock.move.line'
lot_catch_weight_ratio = fields.Float(string='Catch Weight Ratio', digits=(10, 6), default=1.0)
lot_catch_weight_ratio_related = fields.Float(related='lot_id.catch_weight_ratio')
#lot_catch_weight_ratio = fields.Float(related='lot_id.catch_weight_ratio')
# def _action_done(self):
# super(StockMoveLine, self)._action_done()
# for ml in self.filtered(lambda l: l.product_id.tracking == 'serial' and l.lot_id):
# ml.lot_id.catch_weight_ratio = ml.lot_catch_weight_ratio
catch_weight_ratio = fields.Float(string='Catch Weight Ratio', digits=(10, 6), default=1.0)
catch_weight = fields.Float(string='Catch Weight', digits=(10,4))
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')

View File

@@ -41,8 +41,9 @@ def _action_done(self):
# the fly before assigning it to the move line if the user checked both
# `use_create_lots` and `use_existing_lots`.
if ml.lot_name and not ml.lot_id:
lot_catch_weight = ml.catch_weight_uom_id._compute_quantity(ml.catch_weight, ml.product_id.catch_weight_uom_id, rounding_method='DOWN')
lot = self.env['stock.production.lot'].create(
{'name': ml.lot_name, 'product_id': ml.product_id.id, 'catch_weight_ratio': ml.lot_catch_weight_ratio}
{'name': ml.lot_name, 'product_id': ml.product_id.id, 'catch_weight': lot_catch_weight}
)
ml.write({'lot_id': lot.id})
elif not picking_type_id.use_create_lots and not picking_type_id.use_existing_lots: