diff --git a/addons/purchase_requisition/models/purchase_requisition.py b/addons/purchase_requisition/models/purchase_requisition.py index d3614b12003b76ca1ca5fa5646b0c884930604a9..4845aa29ef656e7adff1ff592beea6c00df18c44 100644 --- a/addons/purchase_requisition/models/purchase_requisition.py +++ b/addons/purchase_requisition/models/purchase_requisition.py @@ -168,6 +168,7 @@ class PurchaseRequisitionLine(models.Model): product_uom_id = fields.Many2one('uom.uom', string='Product Unit of Measure', domain="[('category_id', '=', product_uom_category_id)]") product_uom_category_id = fields.Many2one(related='product_id.uom_id.category_id') product_qty = fields.Float(string='Quantity', digits='Product Unit of Measure') + product_description_variants = fields.Char('Custom Description') price_unit = fields.Float(string='Unit Price', digits='Product Price') qty_ordered = fields.Float(compute='_compute_ordered_qty', string='Ordered Quantities') requisition_id = fields.Many2one('purchase.requisition', required=True, string='Purchase Agreement', ondelete='cascade') @@ -243,6 +244,8 @@ class PurchaseRequisitionLine(models.Model): def _prepare_purchase_order_line(self, name, product_qty=0.0, price_unit=0.0, taxes_ids=False): self.ensure_one() requisition = self.requisition_id + if self.product_description_variants: + name += '\n' + self.product_description_variants if requisition.schedule_date: date_planned = datetime.combine(requisition.schedule_date, time.min) else: diff --git a/addons/purchase_requisition/views/purchase_requisition_views.xml b/addons/purchase_requisition/views/purchase_requisition_views.xml index 8e6ac33a874b2dcb3ada38116742a7b3bf7ed8db..345a2b58d8406184bb3abd1344c35e616f339549 100644 --- a/addons/purchase_requisition/views/purchase_requisition_views.xml +++ b/addons/purchase_requisition/views/purchase_requisition_views.xml @@ -151,6 +151,7 @@ <field name="line_ids"> <tree string="Products" editable="bottom"> <field name="product_id" context="{'default_purchase_requisition': 'tenders'}" domain="['|', ('company_id', '=', False), ('company_id', '=', parent.company_id)]"/> + <field name="product_description_variants" attrs="{'readonly': [('parent.state', '!=', 'draft')]}"/> <field name="product_qty"/> <field name="qty_ordered" optional="show"/> <field name="product_uom_category_id" invisible="1"/> diff --git a/addons/purchase_requisition_stock/models/purchase_requisition.py b/addons/purchase_requisition_stock/models/purchase_requisition.py index d490edace07d337ddbcdcc70a828e7742c010a01..a27903246d5e8825c2d065b7c9d4d5e9a61781e9 100644 --- a/addons/purchase_requisition_stock/models/purchase_requisition.py +++ b/addons/purchase_requisition_stock/models/purchase_requisition.py @@ -31,6 +31,7 @@ class PurchaseRequisition(models.Model): 'product_id': product_id.id, 'product_uom_id': product_uom.id, 'product_qty': product_qty, + 'product_description_variants': values.get('product_description_variants'), 'move_dest_id': values.get('move_dest_ids') and values['move_dest_ids'][0].id or False })], } diff --git a/addons/purchase_stock/models/purchase.py b/addons/purchase_stock/models/purchase.py index d07893425edcad8c16a7f4731ab25b7100ae5c50..729f220ac80c276cff67cc4ed52b2131f3eac372 100644 --- a/addons/purchase_stock/models/purchase.py +++ b/addons/purchase_stock/models/purchase.py @@ -458,5 +458,5 @@ class PurchaseOrderLine(models.Model): l.propagate_date_minimum_delta == values['propagate_date_minimum_delta'] and l.propagate_cancel == values['propagate_cancel'] and ((values['orderpoint_id'] and not values['move_dest_ids']) and l.orderpoint_id == values['orderpoint_id'] or True) and - (values.get('product_description_variants') and l.name == description_picking or True)) + (not values.get('product_description_variants') or l.name == description_picking)) return lines and lines[0] or self.env['purchase.order.line'] diff --git a/addons/purchase_stock/tests/test_purchase_lead_time.py b/addons/purchase_stock/tests/test_purchase_lead_time.py index 2706527dd78e64a1421b908b236bb988b811c19b..fd8f81ac201f81456a9c4b5dfa572177dfbdae6b 100644 --- a/addons/purchase_stock/tests/test_purchase_lead_time.py +++ b/addons/purchase_stock/tests/test_purchase_lead_time.py @@ -256,17 +256,18 @@ class TestPurchaseLeadTime(PurchaseTestCommon): 'route_ids': [], } - procurement_values['product_description_variants'] = '[{"color": "Red"}]' - procurement_values['description'] = "T-shirt (Red)" + procurement_values['product_description_variants'] = 'Color (Red)' order_1_values = procurement_values ProcurementGroup.run([self.env['procurement.group'].Procurement( self.t_shirt, 5, self.uom_unit, self.warehouse_1.lot_stock_id, self.t_shirt.name, '/', self.env.company, order_1_values) ]) purchase_order = self.env['purchase.order.line'].search([('product_id', '=', self.t_shirt.id)], limit=1).order_id + order_line_description = purchase_order.order_line.product_id._get_description(purchase_order.picking_type_id) self.assertEqual(len(purchase_order.order_line), 1, 'wrong number of order line is created') + self.assertEqual(purchase_order.order_line.name, order_line_description + "Color (Red)", 'wrong description in po lines') - procurement_values['product_description_variants'] = '[{"color": "Red"}]' + procurement_values['product_description_variants'] = 'Color (Red)' order_2_values = procurement_values ProcurementGroup.run([self.env['procurement.group'].Procurement( self.t_shirt, 10, self.uom_unit, self.warehouse_1.lot_stock_id, @@ -276,8 +277,7 @@ class TestPurchaseLeadTime(PurchaseTestCommon): self.assertEqual(len(purchase_order.order_line), 1, 'line with same custom value should be merged') self.assertEqual(purchase_order.order_line[0].product_qty, 15, 'line with same custom value should be merged and qty should be update') - procurement_values['product_description_variants'] = '[{"color": "Green"}]' - procurement_values['description'] = "T-shirt (Green)" + procurement_values['product_description_variants'] = 'Color (Green)' order_3_values = procurement_values ProcurementGroup.run([self.env['procurement.group'].Procurement( @@ -285,13 +285,12 @@ class TestPurchaseLeadTime(PurchaseTestCommon): self.t_shirt.name, '/', self.env.company, order_3_values) ]) self.assertEqual(len(purchase_order.order_line), 2, 'line with different custom value should not be merged') - self.assertEqual(purchase_order.order_line.filtered(lambda x: x.product_qty == 15).name, "T-shirt (Red)", 'wrong description in po lines') - self.assertEqual(purchase_order.order_line.filtered(lambda x: x.product_qty == 10).name, "T-shirt (Green)", 'wrong description in po lines') + self.assertEqual(purchase_order.order_line.filtered(lambda x: x.product_qty == 15).name, order_line_description + "Color (Red)", 'wrong description in po lines') + self.assertEqual(purchase_order.order_line.filtered(lambda x: x.product_qty == 10).name, order_line_description + "Color (Green)", 'wrong description in po lines') purchase_order.button_confirm() - - self.assertEqual(purchase_order.picking_ids[0].move_ids_without_package.filtered(lambda x: x.product_uom_qty == 15).description_picking, "T-shirt (Red)", 'wrong description in picking') - self.assertEqual(purchase_order.picking_ids[0].move_ids_without_package.filtered(lambda x: x.product_uom_qty == 10).description_picking, "T-shirt (Green)", 'wrong description in picking') + self.assertEqual(purchase_order.picking_ids[0].move_ids_without_package.filtered(lambda x: x.product_uom_qty == 15).description_picking, order_line_description + "Color (Red)", 'wrong description in picking') + self.assertEqual(purchase_order.picking_ids[0].move_ids_without_package.filtered(lambda x: x.product_uom_qty == 10).description_picking, order_line_description + "Color (Green)", 'wrong description in picking') def test_reordering_days_to_purchase(self): self.patcher = patch('odoo.addons.stock.models.stock_orderpoint.fields.Date', wraps=fields.Date)