From f3fc0c2b168cfb88c243af696a65d661ecd63c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Fri, 19 Feb 2021 09:12:18 +0100 Subject: [PATCH] [IMP] sale_stock_available_info_popup: black, isort, prettier --- .../__manifest__.py | 15 +- .../models/sale_order.py | 12 +- .../static/src/xml/qty_at_date.xml | 21 +- .../test_sale_stock_available_info_popup.py | 213 ++++++++++-------- .../views/sale_order_views.xml | 11 +- .../addons/sale_stock_available_info_popup | 1 + .../sale_stock_available_info_popup/setup.py | 6 + 7 files changed, 164 insertions(+), 115 deletions(-) create mode 120000 setup/sale_stock_available_info_popup/odoo/addons/sale_stock_available_info_popup create mode 100644 setup/sale_stock_available_info_popup/setup.py diff --git a/sale_stock_available_info_popup/__manifest__.py b/sale_stock_available_info_popup/__manifest__.py index 84d269086..7679c498a 100644 --- a/sale_stock_available_info_popup/__manifest__.py +++ b/sale_stock_available_info_popup/__manifest__.py @@ -3,21 +3,14 @@ { "name": "Sale Stock Available Info Popup", "summary": "Adds an 'Available to promise' quantity to the popover shown " - "in sale order line that display stock info of the product", + "in sale order line that display stock info of the product", "author": "Tecnativa, Odoo Community Association (OCA)", "website": "https://github.com/OCA/stock-logistics-warehouse", "category": "Warehouse Management", "version": "12.0.1.0.1", "license": "AGPL-3", - "depends": [ - "sale_stock_info_popup", - "stock_available", - ], - "data": [ - "views/sale_order_views.xml", - ], - "qweb": [ - "static/src/xml/qty_at_date.xml", - ], + "depends": ["sale_stock_info_popup", "stock_available",], + "data": ["views/sale_order_views.xml",], + "qweb": ["static/src/xml/qty_at_date.xml",], "installable": True, } diff --git a/sale_stock_available_info_popup/models/sale_order.py b/sale_stock_available_info_popup/models/sale_order.py index 7e510da77..53c6eff34 100644 --- a/sale_stock_available_info_popup/models/sale_order.py +++ b/sale_stock_available_info_popup/models/sale_order.py @@ -7,22 +7,24 @@ from odoo import api, fields, models class SaleOrderLine(models.Model): - _inherit = 'sale.order.line' + _inherit = "sale.order.line" immediately_usable_qty_today = fields.Float( - compute='_compute_immediately_usable_qty_today') + compute="_compute_immediately_usable_qty_today" + ) - @api.depends('product_id', 'product_uom_qty') + @api.depends("product_id", "product_uom_qty") def _compute_immediately_usable_qty_today(self): qty_processed_per_product = defaultdict(lambda: 0) - remaining = self.env['sale.order.line'] + remaining = self.env["sale.order.line"] for line in self.sorted(key=lambda r: r.sequence): if not line.display_qty_widget: remaining |= line continue product = line.product_id qty_processed = qty_processed_per_product[product.id] - line.immediately_usable_qty_today = \ + line.immediately_usable_qty_today = ( product.immediately_usable_qty - qty_processed + ) qty_processed_per_product[product.id] += line.product_uom_qty remaining.write({"immediately_usable_qty_today": False}) diff --git a/sale_stock_available_info_popup/static/src/xml/qty_at_date.xml b/sale_stock_available_info_popup/static/src/xml/qty_at_date.xml index 205eed5e7..dea9486b9 100644 --- a/sale_stock_available_info_popup/static/src/xml/qty_at_date.xml +++ b/sale_stock_available_info_popup/static/src/xml/qty_at_date.xml @@ -1,18 +1,27 @@ - +
- - widget.data.immediately_usable_qty_today < widget.data.qty_to_deliver and !widget.data.is_mto + + widget.data.immediately_usable_qty_today < widget.data.qty_to_deliver and !widget.data.is_mto
- Available to promise - - + + Available to promise + + + + +
diff --git a/sale_stock_available_info_popup/tests/test_sale_stock_available_info_popup.py b/sale_stock_available_info_popup/tests/test_sale_stock_available_info_popup.py index 5ff90f7ab..1dff449e3 100644 --- a/sale_stock_available_info_popup/tests/test_sale_stock_available_info_popup.py +++ b/sale_stock_available_info_popup/tests/test_sale_stock_available_info_popup.py @@ -5,113 +5,148 @@ from odoo.tests.common import SavepointCase class SaleStockAvailableInfoPopup(SavepointCase): - @classmethod def setUpClass(cls): super(SaleStockAvailableInfoPopup, cls).setUpClass() - user_group_stock_user = cls.env.ref('stock.group_stock_user') - cls.user_stock_user = cls.env['res.users'].create({ - 'name': 'Pauline Poivraisselle', - 'login': 'pauline', - 'email': 'p.p@example.com', - 'notification_type': 'inbox', - 'groups_id': [(6, 0, [user_group_stock_user.id])]}) - cls.product = cls.env['product.product'].create({ - 'name': 'Storable product', - 'type': 'product', - }) - cls.stock_location = cls.env.ref('stock.stock_location_stock') - cls.customers_location = cls.env.ref('stock.stock_location_customers') - cls.suppliers_location = cls.env.ref('stock.stock_location_suppliers') - cls.env['stock.quant'].create({ - 'product_id': cls.product.id, - 'location_id': cls.stock_location.id, - 'quantity': 40.0}) - cls.picking_out = cls.env['stock.picking'].create({ - 'picking_type_id': cls.env.ref('stock.picking_type_out').id, - 'location_id': cls.stock_location.id, - 'location_dest_id': cls.customers_location.id}) - cls.env['stock.move'].create({ - 'name': 'a move', - 'product_id': cls.product.id, - 'product_uom_qty': 3.0, - 'product_uom': cls.product.uom_id.id, - 'picking_id': cls.picking_out.id, - 'location_id': cls.stock_location.id, - 'location_dest_id': cls.customers_location.id}) - cls.picking_in = cls.env['stock.picking'].create({ - 'picking_type_id': cls.env.ref('stock.picking_type_in').id, - 'location_id': cls.suppliers_location.id, - 'location_dest_id': cls.stock_location.id}) - cls.env['stock.move'].create({ - 'restrict_partner_id': cls.user_stock_user.partner_id.id, - 'name': 'another move', - 'product_id': cls.product.id, - 'product_uom_qty': 5.0, - 'product_uom': cls.product.uom_id.id, - 'picking_id': cls.picking_in.id, - 'location_id': cls.suppliers_location.id, - 'location_dest_id': cls.stock_location.id}) + user_group_stock_user = cls.env.ref("stock.group_stock_user") + cls.user_stock_user = cls.env["res.users"].create( + { + "name": "Pauline Poivraisselle", + "login": "pauline", + "email": "p.p@example.com", + "notification_type": "inbox", + "groups_id": [(6, 0, [user_group_stock_user.id])], + } + ) + cls.product = cls.env["product.product"].create( + {"name": "Storable product", "type": "product",} + ) + cls.stock_location = cls.env.ref("stock.stock_location_stock") + cls.customers_location = cls.env.ref("stock.stock_location_customers") + cls.suppliers_location = cls.env.ref("stock.stock_location_suppliers") + cls.env["stock.quant"].create( + { + "product_id": cls.product.id, + "location_id": cls.stock_location.id, + "quantity": 40.0, + } + ) + cls.picking_out = cls.env["stock.picking"].create( + { + "picking_type_id": cls.env.ref("stock.picking_type_out").id, + "location_id": cls.stock_location.id, + "location_dest_id": cls.customers_location.id, + } + ) + cls.env["stock.move"].create( + { + "name": "a move", + "product_id": cls.product.id, + "product_uom_qty": 3.0, + "product_uom": cls.product.uom_id.id, + "picking_id": cls.picking_out.id, + "location_id": cls.stock_location.id, + "location_dest_id": cls.customers_location.id, + } + ) + cls.picking_in = cls.env["stock.picking"].create( + { + "picking_type_id": cls.env.ref("stock.picking_type_in").id, + "location_id": cls.suppliers_location.id, + "location_dest_id": cls.stock_location.id, + } + ) + cls.env["stock.move"].create( + { + "restrict_partner_id": cls.user_stock_user.partner_id.id, + "name": "another move", + "product_id": cls.product.id, + "product_uom_qty": 5.0, + "product_uom": cls.product.uom_id.id, + "picking_id": cls.picking_in.id, + "location_id": cls.suppliers_location.id, + "location_dest_id": cls.stock_location.id, + } + ) def test_immediately_usable_qty_today(self): self.picking_out.action_confirm() self.picking_in.action_assign() - so = self.env['sale.order'].create({ - 'partner_id': self.env.ref('base.res_partner_1').id, - 'order_line': [ - (0, 0, { - 'name': self.product.name, - 'product_id': self.product.id, - 'product_uom_qty': 1, - 'product_uom': self.product.uom_id.id, - 'price_unit': self.product.list_price - }), - ], - }) + so = self.env["sale.order"].create( + { + "partner_id": self.env.ref("base.res_partner_1").id, + "order_line": [ + ( + 0, + 0, + { + "name": self.product.name, + "product_id": self.product.id, + "product_uom_qty": 1, + "product_uom": self.product.uom_id.id, + "price_unit": self.product.list_price, + }, + ), + ], + } + ) line = so.order_line self.assertEqual( - line.immediately_usable_qty_today, - self.product.immediately_usable_qty, + line.immediately_usable_qty_today, self.product.immediately_usable_qty, ) def test_immediately_usable_qty_today_similar_solines(self): """Create a sale order containing three times the same product. The quantity available should be different for the 3 lines. """ - so = self.env['sale.order'].create({ - 'partner_id': self.env.ref('base.res_partner_1').id, - 'order_line': [ - (0, 0, { - 'sequence': 1, - 'name': self.product.name, - 'product_id': self.product.id, - 'product_uom_qty': 5, - 'product_uom': self.product.uom_id.id, - 'price_unit': self.product.list_price - }), - (0, 0, { - 'sequence': 2, - 'name': self.product.name, - 'product_id': self.product.id, - 'product_uom_qty': 5, - 'product_uom': self.product.uom_id.id, - 'price_unit': self.product.list_price - }), - (0, 0, { - 'sequence': 3, - 'name': self.product.name, - 'product_id': self.product.id, - 'product_uom_qty': 5, - 'product_uom': self.product.uom_id.id, - 'price_unit': self.product.list_price - }), - ], - }) + so = self.env["sale.order"].create( + { + "partner_id": self.env.ref("base.res_partner_1").id, + "order_line": [ + ( + 0, + 0, + { + "sequence": 1, + "name": self.product.name, + "product_id": self.product.id, + "product_uom_qty": 5, + "product_uom": self.product.uom_id.id, + "price_unit": self.product.list_price, + }, + ), + ( + 0, + 0, + { + "sequence": 2, + "name": self.product.name, + "product_id": self.product.id, + "product_uom_qty": 5, + "product_uom": self.product.uom_id.id, + "price_unit": self.product.list_price, + }, + ), + ( + 0, + 0, + { + "sequence": 3, + "name": self.product.name, + "product_id": self.product.id, + "product_uom_qty": 5, + "product_uom": self.product.uom_id.id, + "price_unit": self.product.list_price, + }, + ), + ], + } + ) self.assertEqual( - so.order_line.mapped('immediately_usable_qty_today'), + so.order_line.mapped("immediately_usable_qty_today"), [ self.product.immediately_usable_qty, self.product.immediately_usable_qty - 5, self.product.immediately_usable_qty - 10, - ] + ], ) diff --git a/sale_stock_available_info_popup/views/sale_order_views.xml b/sale_stock_available_info_popup/views/sale_order_views.xml index d7b3f1a17..52d82ba84 100644 --- a/sale_stock_available_info_popup/views/sale_order_views.xml +++ b/sale_stock_available_info_popup/views/sale_order_views.xml @@ -1,14 +1,17 @@ - + sale.order.line.tree.inherit sale.order - + - - + + diff --git a/setup/sale_stock_available_info_popup/odoo/addons/sale_stock_available_info_popup b/setup/sale_stock_available_info_popup/odoo/addons/sale_stock_available_info_popup new file mode 120000 index 000000000..7ddb79ef2 --- /dev/null +++ b/setup/sale_stock_available_info_popup/odoo/addons/sale_stock_available_info_popup @@ -0,0 +1 @@ +../../../../sale_stock_available_info_popup \ No newline at end of file diff --git a/setup/sale_stock_available_info_popup/setup.py b/setup/sale_stock_available_info_popup/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/sale_stock_available_info_popup/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)