diff --git a/addons/delivery/models/stock_picking.py b/addons/delivery/models/stock_picking.py index b6b9f291d71..344828b27a2 100644 --- a/addons/delivery/models/stock_picking.py +++ b/addons/delivery/models/stock_picking.py @@ -6,6 +6,22 @@ from openerp.exceptions import UserError import openerp.addons.decimal_precision as dp +class StockQuantPackage(models.Model): + _inherit = "stock.quant.package" + + @api.one + @api.depends('quant_ids', 'children_ids') + def _compute_weight(self): + weight = 0 + for quant in self.quant_ids: + weight += quant.qty * quant.product_id.weight + for pack in self.children_ids: + pack._compute_weight() + weight += pack.weight + self.weight = weight + + weight = fields.Float(compute='_compute_weight') + class StockPicking(models.Model): _inherit = 'stock.picking' @@ -14,6 +30,28 @@ class StockPicking(models.Model): uom_categ_id = self.env.ref('product.product_uom_categ_kgm').id return self.env['product.uom'].search([('category_id', '=', uom_categ_id), ('factor', '=', 1)], limit=1) + @api.one + @api.depends('pack_operation_ids') + def _compute_packages(self): + self.ensure_one() + packs = set() + for packop in self.pack_operation_ids: + if packop.result_package_id: + packs.add(packop.result_package_id.id) + elif packop.package_id and not packop.product_id: + packs.add(packop.package_id.id) + self.package_ids = list(packs) + + @api.one + @api.depends('pack_operation_ids') + def _compute_bulk_weight(self): + weight = 0.0 + uom_obj = self.env['product.uom'] + for packop in self.pack_operation_ids: + if packop.product_id and not packop.result_package_id: + weight += uom_obj._compute_qty_obj(packop.product_uom_id , packop.product_qty, packop.product_id.uom_id) * packop.product_id.weight + self.weight_bulk = weight + carrier_price = fields.Float(string="Shipping Cost", readonly=True) delivery_type = fields.Selection(related='carrier_id.delivery_type', readonly=True) carrier_id = fields.Many2one("delivery.carrier", string="Carrier") @@ -22,6 +60,8 @@ class StockPicking(models.Model): carrier_tracking_ref = fields.Char(string='Carrier Tracking Ref', copy=False) number_of_packages = fields.Integer(string='Number of Packages', copy=False) weight_uom_id = fields.Many2one('product.uom', string='Unit of Measure', required=True, readonly="1", help="Unit of measurement for Weight", default=_default_uom) + package_ids = fields.Many2many('stock.quant.package', compute='_compute_packages', string='Packages') + weight_bulk = fields.Float('Bulk Weight', compute='_compute_bulk_weight') @api.depends('product_id', 'move_lines') def _cal_weight(self): diff --git a/addons/delivery/views/delivery_view.xml b/addons/delivery/views/delivery_view.xml index 6d7525be2b8..2b6fbae5902 100644 --- a/addons/delivery/views/delivery_view.xml +++ b/addons/delivery/views/delivery_view.xml @@ -195,6 +195,17 @@ + + stock.quant.package.weight.form + stock.quant.package + + + + + + + + stock.move.form.weight stock.move diff --git a/addons/product/product_view.xml b/addons/product/product_view.xml index ea959d44c15..617c471dddc 100644 --- a/addons/product/product_view.xml +++ b/addons/product/product_view.xml @@ -125,11 +125,9 @@ - @@ -482,12 +480,12 @@ - - - - + +
+ {'invisible':[('type', 'not in', ['product', 'consu'])]} +