-
-
Notifications
You must be signed in to change notification settings - Fork 790
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] purchase_manual_delivery: Migration to 18.0
* Move models and views into their own model file * Integrate with purchase_order_line_menu
- Loading branch information
1 parent
28b6bb3
commit 2c24f7e
Showing
9 changed files
with
132 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
from . import res_company | ||
from . import res_config | ||
from . import purchase_order | ||
from . import purchase_order_line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
purchase_manual_delivery/views/purchase_order_line_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
|
||
<record id="purchase_order_line_tree" model="ir.ui.view"> | ||
<field name="model">purchase.order.line</field> | ||
<field name="inherit_id" ref="purchase.purchase_order_line_tree" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="/list" position="attributes"> | ||
<attribute | ||
name="decoration-info" | ||
>state == 'purchase' and pending_to_receive</attribute> | ||
</xpath> | ||
<field name="product_qty" position="after"> | ||
<field name="qty_in_receipt" /> | ||
</field> | ||
<field name="date_planned" position="after"> | ||
<field name="pending_to_receive" optional="hide" /> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
<record id="purchase_order_line_search" model="ir.ui.view"> | ||
<field name="model">purchase.order.line</field> | ||
<field name="inherit_id" ref="purchase.purchase_order_line_search" /> | ||
<field name="arch" type="xml"> | ||
<group position="before"> | ||
<separator /> | ||
<filter | ||
string="Reception confirmed" | ||
name="received" | ||
domain="[('pending_to_receive','=', False), ('state', '=', 'purchase')]" | ||
help="Purchase Order Lines that are confirmed or done and an incoming shipment is created to satisfy them" | ||
/> | ||
<filter | ||
string="Pending to receive" | ||
name="unreceived" | ||
domain="[('pending_to_receive','=', True), ('state', '=', 'purchase')]" | ||
help="Purchase Order Lines that are confirmed or done and no incoming shipment is created to satisfy them" | ||
/> | ||
</group> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
git+https://github.com/stefanrijnhart/purchase-workflow@18.0-mig-purchase_order_line_menu#subdirectory=purchase_order_line_menu |