diff --git a/purchase_manual_delivery/__manifest__.py b/purchase_manual_delivery/__manifest__.py index ca555864932..f18e10981e3 100644 --- a/purchase_manual_delivery/__manifest__.py +++ b/purchase_manual_delivery/__manifest__.py @@ -8,14 +8,15 @@ and adds the ability to manually generate them as the supplier confirms the different purchase order lines. """, - "version": "17.0.1.0.0", + "version": "18.0.1.0.0", "license": "AGPL-3", "author": "ForgeFlow S.L.," "Odoo Community Association (OCA)", "website": "https://github.com/OCA/purchase-workflow", - "depends": ["purchase_stock"], + "depends": ["purchase_stock", "purchase_order_line_menu"], "data": [ "security/ir.model.access.csv", "wizard/create_manual_stock_picking.xml", + "views/purchase_order_line_views.xml", "views/purchase_order_views.xml", "views/res_config_view.xml", ], diff --git a/purchase_manual_delivery/models/__init__.py b/purchase_manual_delivery/models/__init__.py index cc495f489cd..e60e2983989 100644 --- a/purchase_manual_delivery/models/__init__.py +++ b/purchase_manual_delivery/models/__init__.py @@ -2,3 +2,4 @@ from . import res_company from . import res_config from . import purchase_order +from . import purchase_order_line diff --git a/purchase_manual_delivery/models/purchase_order.py b/purchase_manual_delivery/models/purchase_order.py index d076db7fd0c..6937963495c 100644 --- a/purchase_manual_delivery/models/purchase_order.py +++ b/purchase_manual_delivery/models/purchase_order.py @@ -2,7 +2,6 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models -from odoo.tools import float_compare class PurchaseOrder(models.Model): @@ -47,75 +46,3 @@ def _create_picking(self): # if it comes from manual confirmation return return super()._create_picking() - - -class PurchaseOrderLine(models.Model): - _inherit = "purchase.order.line" - - qty_in_receipt = fields.Float( - compute="_compute_qty_in_receipt", - store=True, - digits="Product Unit of Measure", - help="Quantity for which there are pending stock moves", - ) - pending_to_receive = fields.Boolean( - compute="_compute_qty_in_receipt", - store=True, - string="Pending Qty to Receive", - help="There is pending quantity to receive not yet planned", - ) - - @api.depends( - "move_ids", - "move_ids.state", - "move_ids.location_id", - "move_ids.location_dest_id", - "product_uom_qty", - "qty_received", - "state", - ) - def _compute_qty_in_receipt(self): - for line in self: - precision_digits = self.env["decimal.precision"].precision_get( - "Product Unit of Measure" - ) - total = 0.0 - for move in line.move_ids: - if move.state not in ["cancel", "done"]: - if ( - move.location_id - == self.order_id.picking_type_id.default_location_dest_id - ): - # This is a return to vendor - if move.to_refund: - total -= move.product_uom._compute_quantity( - move.quantity, line.product_uom - ) - elif ( - move.origin_returned_move_id - and move.origin_returned_move_id._is_dropshipped() - and not move._is_dropshipped_returned() - ): - # Edge case: the dropship is returned to the stock, - # no to the supplier. - # In this case, the received quantity on the PO is - # set although we didn't receive the product - # physically in our stock. To avoid counting the - # quantity twice, we do nothing. - pass - else: - total += move.product_uom._compute_quantity( - move.quantity, line.product_uom - ) - line.qty_in_receipt = total - if ( - float_compare( - line.product_qty, - line.qty_in_receipt + line.qty_received, - precision_digits=precision_digits, - ) - == 1 - ): - line.pending_to_receive = True - else: - line.pending_to_receive = False diff --git a/purchase_manual_delivery/models/purchase_order_line.py b/purchase_manual_delivery/models/purchase_order_line.py new file mode 100644 index 00000000000..0a5e099d224 --- /dev/null +++ b/purchase_manual_delivery/models/purchase_order_line.py @@ -0,0 +1,77 @@ +# Copyright 2019 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models +from odoo.tools import float_compare + + +class PurchaseOrderLine(models.Model): + _inherit = "purchase.order.line" + + qty_in_receipt = fields.Float( + compute="_compute_qty_in_receipt", + store=True, + digits="Product Unit of Measure", + help="Quantity for which there are pending stock moves", + ) + pending_to_receive = fields.Boolean( + compute="_compute_qty_in_receipt", + store=True, + string="Pending Qty to Receive", + help="There is pending quantity to receive not yet planned", + ) + + @api.depends( + "move_ids", + "move_ids.state", + "move_ids.location_id", + "move_ids.location_dest_id", + "product_uom_qty", + "qty_received", + "state", + ) + def _compute_qty_in_receipt(self): + for line in self: + precision_digits = self.env["decimal.precision"].precision_get( + "Product Unit of Measure" + ) + total = 0.0 + for move in line.move_ids: + if move.state not in ["cancel", "done"]: + if ( + move.location_id + == self.order_id.picking_type_id.default_location_dest_id + ): + # This is a return to vendor + if move.to_refund: + total -= move.product_uom._compute_quantity( + move.quantity, line.product_uom + ) + elif ( + move.origin_returned_move_id + and move.origin_returned_move_id._is_dropshipped() + and not move._is_dropshipped_returned() + ): + # Edge case: the dropship is returned to the stock, + # no to the supplier. + # In this case, the received quantity on the PO is + # set although we didn't receive the product + # physically in our stock. To avoid counting the + # quantity twice, we do nothing. + pass + else: + total += move.product_uom._compute_quantity( + move.quantity, line.product_uom + ) + line.qty_in_receipt = total + if ( + float_compare( + line.product_qty, + line.qty_in_receipt + line.qty_received, + precision_digits=precision_digits, + ) + == 1 + ): + line.pending_to_receive = True + else: + line.pending_to_receive = False diff --git a/purchase_manual_delivery/tests/test_purchase_manual_delivery.py b/purchase_manual_delivery/tests/test_purchase_manual_delivery.py index 8603dc4f71b..87579e76742 100644 --- a/purchase_manual_delivery/tests/test_purchase_manual_delivery.py +++ b/purchase_manual_delivery/tests/test_purchase_manual_delivery.py @@ -3,7 +3,7 @@ from odoo import fields from odoo.exceptions import UserError -from odoo.tests.common import Form, TransactionCase +from odoo.tests import Form, TransactionCase from odoo.addons.mail.tests.common import mail_new_test_user @@ -207,7 +207,7 @@ def test_01_purchase_order_manual_delivery(self): "to_refund": False, } ) - return_wiz.create_returns() + return_wiz.action_create_returns() # The refund line is open to re-receive the returned item self.assertTrue(self.po1_line1.pending_to_receive) @@ -369,7 +369,7 @@ def test_05_purchase_order_in_progress(self): product_in_progress = self.env["product.product"].create( { "name": "Test product pending", - "type": "product", + "type": "consu", "list_price": 1, "standard_price": 1, } diff --git a/purchase_manual_delivery/views/purchase_order_line_views.xml b/purchase_manual_delivery/views/purchase_order_line_views.xml new file mode 100644 index 00000000000..bd5b3f8b5b9 --- /dev/null +++ b/purchase_manual_delivery/views/purchase_order_line_views.xml @@ -0,0 +1,44 @@ + + + + + purchase.order.line + + + + state == 'purchase' and pending_to_receive + + + + + + + + + + + + purchase.order.line + + + + + + + + + + + diff --git a/purchase_manual_delivery/views/purchase_order_views.xml b/purchase_manual_delivery/views/purchase_order_views.xml index 693d0779768..dcccbd55ba2 100644 --- a/purchase_manual_delivery/views/purchase_order_views.xml +++ b/purchase_manual_delivery/views/purchase_order_views.xml @@ -49,7 +49,7 @@ column_invisible="parent.state not in ('purchase', 'done')" /> - + state == 'purchase' and pending_to_receive @@ -63,77 +63,4 @@ - - purchase.order.line - - - - state == 'purchase' and pending_to_receive - - - - - - - - - - - - - purchase.order.unreceived.line - purchase.order.line - - - - - - - - - - - - - - - Purchase Manual Receipt - ir.actions.act_window - purchase.order.line - tree,form - - {"search_default_unreceived":0, "search_default_received":0} - - -

- Here is a list of each purchase order line to be received. -

-
-
- - - diff --git a/purchase_manual_delivery/wizard/create_manual_stock_picking.xml b/purchase_manual_delivery/wizard/create_manual_stock_picking.xml index 1a690f50510..efe3a8f6e12 100644 --- a/purchase_manual_delivery/wizard/create_manual_stock_picking.xml +++ b/purchase_manual_delivery/wizard/create_manual_stock_picking.xml @@ -24,7 +24,7 @@ /> - + @@ -36,7 +36,7 @@ - +