diff --git a/mrp_sale_info/models/mrp_production.py b/mrp_sale_info/models/mrp_production.py index d840d54c7..9b16a654a 100644 --- a/mrp_sale_info/models/mrp_production.py +++ b/mrp_sale_info/models/mrp_production.py @@ -8,7 +8,8 @@ from odoo import api, fields, models class MrpProduction(models.Model): _inherit = "mrp.production" - sale_id = fields.Many2one('sale.order', compute='_compute_sale_info', string='Sale order', + sale_id = fields.Many2one('sale.order', compute='_compute_sale_info', + string='Sale order', readonly=True) partner_id = fields.Many2one('res.partner', compute='_compute_sale_info', string='Customer') @@ -24,7 +25,11 @@ class MrpProduction(models.Model): for production in self: move = get_parent_move(production.move_finished_ids) - production.sale_id = move.procurement_id and move.procurement_id.sale_line_id and \ - move.procurement_id.sale_line_id.order_id.id or False - production.partner_id = production.sale_id and production.sale_id.partner_id and production.sale_id.partner_id.id or False - production.commitment_date = production.sale_id and production.sale_id.commitment_date or '' + proc = move.procurement_id + production.sale_id = proc and proc.sale_line_id and \ + proc.sale_line_id.order_id.id or False + production.partner_id = production.sale_id and \ + production.sale_id.partner_id and \ + production.sale_id.partner_id.id or False + production.commitment_date = production.sale_id and \ + production.sale_id.commitment_date or '' diff --git a/mrp_sale_info/tests/test_sale_manufacture.py b/mrp_sale_info/tests/test_sale_manufacture.py index c150e29b3..6275e7efc 100644 --- a/mrp_sale_info/tests/test_sale_manufacture.py +++ b/mrp_sale_info/tests/test_sale_manufacture.py @@ -24,13 +24,17 @@ class TestManufactureSale(TransactionCase): 'partner_id': self.partner.id, 'partner_invoice_id': self.partner.id, 'partner_shipping_id': self.partner.id, - 'order_line': [(0, 0, {'name': product.name, 'product_id': product.id, 'product_uom_qty': 1, 'product_uom': product.uom_id.id, + 'order_line': [(0, 0, {'name': product.name, + 'product_id': product.id, + 'product_uom_qty': 1, + 'product_uom': product.uom_id.id, 'price_unit': product.list_price}) ], 'pricelist_id': self.env.ref('product.list0').id, }) so.action_confirm() - mrp = self.mrp_production.search([('origin', 'like', so.name+'%')], limit=1) + mrp = self.mrp_production.search([('origin', 'like', so.name+'%')], + limit=1) # checking sale info filled correctly on manufacture self.assertEqual(so.id, mrp.sale_id.id) self.assertEqual(self.partner.id, mrp.partner_id.id)