mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
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.
47 lines
2.1 KiB
Python
47 lines
2.1 KiB
Python
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), 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'
|
|
|
|
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')
|