From f9c51603d6678a9d0879e76878a99277ef6281d0 Mon Sep 17 00:00:00 2001 From: Kevin Khao Date: Wed, 21 Apr 2021 14:20:33 +0200 Subject: [PATCH] [IMP] mrp_sale_info: black, isort, prettier --- mrp_sale_info/__manifest__.py | 10 ++--- mrp_sale_info/models/mrp_production.py | 22 +++++++--- mrp_sale_info/models/mrp_workorder.py | 19 ++++++--- mrp_sale_info/models/stock_rule.py | 23 +++++++--- mrp_sale_info/tests/test_mrp_sale_info.py | 52 ++++++++++++++--------- mrp_sale_info/views/mrp_production.xml | 16 +++---- mrp_sale_info/views/mrp_workorder.xml | 20 ++++----- 7 files changed, 96 insertions(+), 66 deletions(-) diff --git a/mrp_sale_info/__manifest__.py b/mrp_sale_info/__manifest__.py index 1bff5fff9..cfbcb67f4 100644 --- a/mrp_sale_info/__manifest__.py +++ b/mrp_sale_info/__manifest__.py @@ -7,13 +7,11 @@ "summary": "Adds sale information to Manufacturing models", "version": "12.0.1.0.0", "category": "Manufacturing", - "website": "https://github.com/oca/manufacture", - "author": "AvanzOSC, " - "Tecnativa, " - "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/manufacture", + "author": "AvanzOSC, " "Tecnativa, " "Odoo Community Association (OCA)", "license": "AGPL-3", "application": False, - 'installable': True, + "installable": True, "depends": [ "mrp", "sale_stock", @@ -21,5 +19,5 @@ "data": [ "views/mrp_production.xml", "views/mrp_workorder.xml", - ] + ], } diff --git a/mrp_sale_info/models/mrp_production.py b/mrp_sale_info/models/mrp_production.py index c6a0bc054..53604a520 100644 --- a/mrp_sale_info/models/mrp_production.py +++ b/mrp_sale_info/models/mrp_production.py @@ -10,14 +10,22 @@ class MrpProduction(models.Model): _inherit = "mrp.production" source_procurement_group_id = fields.Many2one( - comodel_name='procurement.group', readonly=True, + comodel_name="procurement.group", + readonly=True, ) sale_id = fields.Many2one( - comodel_name='sale.order', string='Sale order', readonly=True, - store=True, related='source_procurement_group_id.sale_id') + comodel_name="sale.order", + string="Sale order", + readonly=True, + store=True, + related="source_procurement_group_id.sale_id", + ) partner_id = fields.Many2one( - comodel_name='res.partner', related='sale_id.partner_id', - string='Customer', store=True) + comodel_name="res.partner", + related="sale_id.partner_id", + string="Customer", + store=True, + ) commitment_date = fields.Datetime( - related='sale_id.commitment_date', string='Commitment Date', - store=True) + related="sale_id.commitment_date", string="Commitment Date", store=True + ) diff --git a/mrp_sale_info/models/mrp_workorder.py b/mrp_sale_info/models/mrp_workorder.py index e9126a376..5c97ddb62 100644 --- a/mrp_sale_info/models/mrp_workorder.py +++ b/mrp_sale_info/models/mrp_workorder.py @@ -8,10 +8,15 @@ from odoo import fields, models class MrpWorkorder(models.Model): _inherit = "mrp.workorder" - sale_id = fields.Many2one(related='production_id.sale_id', - string='Sale order', readonly=True, store=True) - partner_id = fields.Many2one(related='sale_id.partner_id', readonly=True, - string='Customer', store=True) - commitment_date = fields.Datetime(related='sale_id.commitment_date', - string='Commitment Date', store=True, - readonly=True) + sale_id = fields.Many2one( + related="production_id.sale_id", string="Sale order", readonly=True, store=True + ) + partner_id = fields.Many2one( + related="sale_id.partner_id", readonly=True, string="Customer", store=True + ) + commitment_date = fields.Datetime( + related="sale_id.commitment_date", + string="Commitment Date", + store=True, + readonly=True, + ) diff --git a/mrp_sale_info/models/stock_rule.py b/mrp_sale_info/models/stock_rule.py index f01c845f3..28a864688 100644 --- a/mrp_sale_info/models/stock_rule.py +++ b/mrp_sale_info/models/stock_rule.py @@ -6,14 +6,23 @@ from odoo import models class StockRule(models.Model): - _inherit = 'stock.rule' + _inherit = "stock.rule" - def _prepare_mo_vals(self, product_id, product_qty, product_uom, - location_id, name, origin, values, bom): + def _prepare_mo_vals( + self, + product_id, + product_qty, + product_uom, + location_id, + name, + origin, + values, + bom, + ): res = super()._prepare_mo_vals( - product_id, product_qty, product_uom, location_id, name, - origin, values, bom + product_id, product_qty, product_uom, location_id, name, origin, values, bom + ) + res["source_procurement_group_id"] = ( + values.get("group_id").id if values.get("group_id", False) else False ) - res["source_procurement_group_id"] = values.get( - "group_id").id if values.get('group_id', False) else False return res diff --git a/mrp_sale_info/tests/test_mrp_sale_info.py b/mrp_sale_info/tests/test_mrp_sale_info.py index a467d7b8d..7b242286c 100644 --- a/mrp_sale_info/tests/test_mrp_sale_info.py +++ b/mrp_sale_info/tests/test_mrp_sale_info.py @@ -8,28 +8,38 @@ class TestMrpSaleInfo(common.SavepointCase): @classmethod def setUpClass(cls): super().setUpClass() - cls.product = cls.env["product.product"].create({ - "name": "Test mrp_sale_info product", - "type": "product", - "route_ids": [ - (4, cls.env.ref("mrp.route_warehouse0_manufacture").id), - (4, cls.env.ref("stock.route_warehouse0_mto").id), - ], - }) - cls.bom = cls.env["mrp.bom"].create({ - "product_tmpl_id": cls.product.product_tmpl_id.id, - }) + cls.product = cls.env["product.product"].create( + { + "name": "Test mrp_sale_info product", + "type": "product", + "route_ids": [ + (4, cls.env.ref("mrp.route_warehouse0_manufacture").id), + (4, cls.env.ref("stock.route_warehouse0_mto").id), + ], + } + ) + cls.bom = cls.env["mrp.bom"].create( + { + "product_tmpl_id": cls.product.product_tmpl_id.id, + } + ) cls.partner = cls.env["res.partner"].create({"name": "Test client"}) - cls.sale_order = cls.env["sale.order"].create({ - "partner_id": cls.partner.id, - "order_line": [ - (0, 0, { - "product_id": cls.product.id, - "product_uom_qty": 1, - "price_unit": 1, - }), - ] - }) + cls.sale_order = cls.env["sale.order"].create( + { + "partner_id": cls.partner.id, + "order_line": [ + ( + 0, + 0, + { + "product_id": cls.product.id, + "product_uom_qty": 1, + "price_unit": 1, + }, + ), + ], + } + ) def test_mrp_sale_info(self): prev_productions = self.env["mrp.production"].search([]) diff --git a/mrp_sale_info/views/mrp_production.xml b/mrp_sale_info/views/mrp_production.xml index 93d4357f6..8a06052f7 100644 --- a/mrp_sale_info/views/mrp_production.xml +++ b/mrp_sale_info/views/mrp_production.xml @@ -1,4 +1,4 @@ - + MRP Production Form with Sale Order @@ -6,9 +6,9 @@ - - - + + + @@ -16,12 +16,12 @@ MRP Production Tree with Sale Order mrp.production - + - - - + + + diff --git a/mrp_sale_info/views/mrp_workorder.xml b/mrp_sale_info/views/mrp_workorder.xml index 8d7317605..6488d3c97 100644 --- a/mrp_sale_info/views/mrp_workorder.xml +++ b/mrp_sale_info/views/mrp_workorder.xml @@ -1,14 +1,14 @@ - + MRP Work Order Tree with Sale Order mrp.workorder - + - - - + + + @@ -16,12 +16,12 @@ MRP Work Order Form with Sale Order mrp.workorder - + - - - - + + + +