Skip to content

Commit

Permalink
[MIG] purchase_manual_delivery: Migration to 18.0
Browse files Browse the repository at this point in the history
* Move models and views into their own model file
* Integrate with purchase_order_line_menu
  • Loading branch information
StefanRijnhart committed Oct 10, 2024
1 parent 28b6bb3 commit 2c24f7e
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 154 deletions.
5 changes: 3 additions & 2 deletions purchase_manual_delivery/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
1 change: 1 addition & 0 deletions purchase_manual_delivery/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
from . import res_company
from . import res_config
from . import purchase_order
from . import purchase_order_line
73 changes: 0 additions & 73 deletions purchase_manual_delivery/models/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
77 changes: 77 additions & 0 deletions purchase_manual_delivery/models/purchase_order_line.py
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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
}
Expand Down
44 changes: 44 additions & 0 deletions purchase_manual_delivery/views/purchase_order_line_views.xml
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>
75 changes: 1 addition & 74 deletions purchase_manual_delivery/views/purchase_order_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
column_invisible="parent.state not in ('purchase', 'done')"
/>
</field>
<xpath expr="//field[@name='order_line']/tree" position="attributes">
<xpath expr="//field[@name='order_line']/list" position="attributes">
<attribute
name="decoration-info"
>state == 'purchase' and pending_to_receive</attribute>
Expand All @@ -63,77 +63,4 @@
</field>
</record>

<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="/tree" 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 name="state" invisible="1" />
</field>
</field>
</record>

<record id="view_purchase_order_unreceived_line_filter" model="ir.ui.view">
<field name="name">purchase.order.unreceived.line</field>
<field name="model">purchase.order.line</field>
<field name="arch" type="xml">
<search string="Search Undelivered Lines">
<field name="order_id" />
<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 expand="0" string="Group By">
<filter
name="purchase"
string="Purchase Order"
context="{'group_by':'order_id'}"
/>
</group>
</search>
</field>
</record>

<record id="action_order_line_delivery_tree" model="ir.actions.act_window">
<field name="name">Purchase Manual Receipt</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">purchase.order.line</field>
<field name="view_mode">tree,form</field>
<field name="search_view_id" ref="view_purchase_order_unreceived_line_filter" />
<field
name="context"
>{"search_default_unreceived":0, "search_default_received":0}</field>
<field name="filter" eval="True" />
<field name="help" type="html">
<p>
Here is a list of each purchase order line to be received.
</p>
</field>
</record>

<menuitem
id="menu_delivery_purchase_order_lines"
parent="purchase.menu_procurement_management"
action="action_order_line_delivery_tree"
sequence="7"
/>

</odoo>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/>
</group>
<field name="line_ids" nolabel="1">
<tree create="false" editable="bottom">
<list create="false" editable="bottom">
<field name="purchase_order_line_id" column_invisible="1" />
<field name="product_id" />
<field name="partner_id" />
Expand All @@ -36,7 +36,7 @@
<field name="remaining_qty" string="Remaining Qty" />
<field name="qty" string="Quantity" />
<field name="product_uom" groups="uom.group_uom" />
</tree>
</list>
</field>
<footer>
<button
Expand Down
1 change: 1 addition & 0 deletions test-requirements.txt
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

0 comments on commit 2c24f7e

Please sign in to comment.