Skip to content

Commit e793ec6

Browse files
committed
[15.0][MIG]sale_backorder
1 parent 0576f73 commit e793ec6

File tree

12 files changed

+136
-122
lines changed

12 files changed

+136
-122
lines changed

sale_backorder/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
{
55
"name": "Sale Backorder Report",
6-
"version": "14.0.1.0.0",
6+
"version": "15.0.1.0.0",
77
"license": "LGPL-3",
88
"author": "Open Source Integrators, Odoo Community Association (OCA)",
99
"summary": "Report of Un-Invoice Goods Delivered and Backorders",

sale_backorder/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
22

33
from . import sale
4+
from . import sale_order_line

sale_backorder/models/sale.py

Lines changed: 14 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,39 @@
1-
# Copyright (C) 2019 - TODAY, Open Source Integrators
1+
# Copyright (C) 2022 - TODAY, Open Source Integrators
22
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
33

44
from odoo import api, fields, models
5-
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
65

76

87
class SaleOrder(models.Model):
98
_inherit = "sale.order"
109

1110
last_date_delivered = fields.Datetime(
12-
string="Last Date Delivered", compute="_compute_last_date_delivered", store=True
11+
string="Date Delivered", compute="_compute_last_date_delivered", store=True
1312
)
1413
last_bill_date = fields.Datetime(
15-
string="Last Bill Date", compute="_compute_last_bill_date", store=True
14+
string="Bill Date", compute="_compute_last_bill_date", store=True
1615
)
17-
uigd_value = fields.Monetary(
18-
string="UIGD Value", compute="_compute_uigd_value", store=True
16+
uninvoiced_goods_delivered_value = fields.Monetary(
17+
string="UIGD Value",
18+
compute="_compute_uigd_value",
19+
store=True,
20+
help="Un-Invoiced Goods Delivered Value",
1921
)
2022
bo_value = fields.Monetary(
2123
string="Backorder Value", compute="_compute_bo_value", store=True
2224
)
2325

24-
@api.depends("order_line.uigd_qty", "order_line.price_unit")
26+
@api.depends("order_line.uninvoiced_goods_delivered_value")
2527
def _compute_uigd_value(self):
2628
for order in self:
27-
total = 0
28-
for line in order.order_line:
29-
total += line.uigd_value
30-
order.uigd_value = total
29+
order.uninvoiced_goods_delivered_value = sum(
30+
order.order_line.mapped("uninvoiced_goods_delivered_value")
31+
)
3132

32-
@api.depends("order_line.bo_qty", "order_line.price_unit")
33+
@api.depends("order_line.bo_value")
3334
def _compute_bo_value(self):
3435
for order in self:
35-
total = 0
36-
for line in order.order_line:
37-
total += line.bo_value
38-
order.bo_value = total
36+
order.bo_value = sum(order.order_line.mapped("bo_value"))
3937

4038
@api.depends(
4139
"order_line.last_date_delivered",
@@ -62,77 +60,3 @@ def _compute_last_bill_date(self):
6260
if line.last_bill_date:
6361
max_date = line.last_bill_date
6462
order.last_bill_date = max_date
65-
66-
67-
class SaleOrderLine(models.Model):
68-
_inherit = "sale.order.line"
69-
70-
last_date_delivered = fields.Datetime(
71-
string="Last Date Delivered", compute="_compute_last_date_delivered", store=True
72-
)
73-
last_bill_date = fields.Datetime(
74-
string="Last Bill Date", compute="_compute_last_bill_date", store=True
75-
)
76-
uigd_qty = fields.Float(string="UIGD Qty", compute="_compute_uigd_qty", store=True)
77-
bo_qty = fields.Float(string="Backorder Qty", compute="_compute_bo_qty", store=True)
78-
uigd_value = fields.Monetary(
79-
string="UIGD Value", compute="_compute_uigd_value", store=True
80-
)
81-
bo_value = fields.Monetary(
82-
string="Backorder Value", compute="_compute_bo_value", store=True
83-
)
84-
product_type = fields.Selection(
85-
string="Product Type", related="product_id.product_tmpl_id.type"
86-
)
87-
88-
@api.depends("qty_delivered", "product_uom_qty")
89-
def _compute_bo_qty(self):
90-
for line in self:
91-
line.bo_qty = line.product_uom_qty - line.qty_delivered
92-
93-
@api.depends("qty_delivered", "qty_invoiced")
94-
def _compute_uigd_qty(self):
95-
for line in self:
96-
line.uigd_qty = line.qty_delivered - line.qty_invoiced
97-
98-
@api.depends("uigd_qty", "price_unit")
99-
def _compute_uigd_value(self):
100-
for line in self:
101-
line.uigd_value = line.uigd_qty * line.price_unit
102-
103-
@api.depends("bo_qty", "price_unit")
104-
def _compute_bo_value(self):
105-
for line in self:
106-
line.bo_value = line.bo_qty * line.price_unit
107-
108-
@api.depends("qty_delivered", "qty_invoiced")
109-
def _compute_last_date_delivered(self):
110-
for line in self:
111-
max_date = False
112-
for move in line.move_ids:
113-
if (
114-
move.state == "done"
115-
and move.location_dest_id.usage == "customer"
116-
and move.to_refund
117-
):
118-
continue
119-
else:
120-
max_date = move.date
121-
line.last_date_delivered = max_date
122-
123-
@api.depends("qty_delivered", "qty_invoiced")
124-
def _compute_last_bill_date(self):
125-
for line in self:
126-
max_date = False
127-
for inv_line in line.invoice_lines:
128-
if (
129-
inv_line.move_id.state != "cancel"
130-
and inv_line.move_id.move_type == "out_invoice"
131-
and inv_line.move_id.date
132-
):
133-
max_date = inv_line.move_id.date
134-
elif inv_line.move_id.move_type == "out_refund":
135-
continue
136-
line.last_bill_date = (
137-
max_date and max_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT) or False
138-
)
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Copyright (C) 2022 - TODAY, Open Source Integrators
2+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3+
4+
from odoo import api, fields, models
5+
6+
7+
class SaleOrderLine(models.Model):
8+
_inherit = "sale.order.line"
9+
10+
last_date_delivered = fields.Datetime(
11+
string="Date Delivered", compute="_compute_last_date_delivered", store=True
12+
)
13+
last_bill_date = fields.Datetime(
14+
string="Bill Date", compute="_compute_last_bill_date", store=True
15+
)
16+
uninvoiced_goods_delivered_qty = fields.Float(
17+
string="UIGD Qty",
18+
compute="_compute_uigd_qty",
19+
store=True,
20+
help="Un-Invoiced Goods Delivered Qty",
21+
)
22+
bo_qty = fields.Float(string="Backorder Qty", compute="_compute_bo_qty", store=True)
23+
uninvoiced_goods_delivered_value = fields.Monetary(
24+
string="UIGD Value",
25+
compute="_compute_uigd_value",
26+
store=True,
27+
help="Un-Invoiced Goods Delivered Value",
28+
)
29+
bo_value = fields.Monetary(
30+
string="Backorder Value", compute="_compute_bo_value", store=True
31+
)
32+
product_type = fields.Selection(
33+
string="Product Type", related="product_id.product_tmpl_id.type"
34+
)
35+
36+
@api.depends("qty_delivered", "product_uom_qty")
37+
def _compute_bo_qty(self):
38+
for line in self:
39+
line.bo_qty = line.product_uom_qty - line.qty_delivered
40+
41+
@api.depends("qty_delivered", "qty_invoiced")
42+
def _compute_uigd_qty(self):
43+
for line in self:
44+
line.uninvoiced_goods_delivered_qty = line.qty_delivered - line.qty_invoiced
45+
46+
@api.depends("uninvoiced_goods_delivered_qty", "price_unit")
47+
def _compute_uigd_value(self):
48+
for line in self:
49+
line.uninvoiced_goods_delivered_value = (
50+
line.uninvoiced_goods_delivered_qty * line.price_unit
51+
)
52+
53+
@api.depends("bo_qty", "price_unit")
54+
def _compute_bo_value(self):
55+
for line in self:
56+
line.bo_value = line.bo_qty * line.price_unit
57+
58+
@api.depends("qty_delivered", "qty_invoiced")
59+
def _compute_last_date_delivered(self):
60+
for line in self:
61+
moves = line.move_ids.sorted("id", reverse=True).filtered(
62+
lambda move: move.state != "done"
63+
or move.location_dest_id.usage != "customer"
64+
or not move.to_refund
65+
)
66+
line.last_date_delivered = moves and moves[0].date or False
67+
68+
@api.depends("qty_delivered", "qty_invoiced")
69+
def _compute_last_bill_date(self):
70+
for line in self:
71+
invoices = line.invoice_lines.sorted("id", reverse=True).filtered(
72+
lambda inv: inv.move_id.state != "cancel"
73+
or inv.move_id.move_type == "out_invoice"
74+
or inv.move_id.date
75+
)
76+
line.last_bill_date = invoices and invoices[0].move_id.date or False

sale_backorder/readme/CONTRIBUTORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
* Sandip Mangukiya <smangukiya@opensourceintegrators.com>
33
* Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com>
44
* Freni Patel <fpatel@opensourceintegrators.com>
5+
* Vandan Pandeji <vpandeji@opensourceintegrators.com>

sale_backorder/report/so_backorder_report.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
<template id="so_backorder_report">
55
<t t-call="web.html_container">
66
<t t-call="web.external_layout">
7-
<br />
87
<div class="page">
9-
<h2>PO Backorder Report</h2>
8+
<br />
9+
<h2>SO Backorder Report</h2>
1010
<table class="table table-sm table-condensed">
1111
<thead>
1212
<tr>
@@ -31,10 +31,10 @@
3131
t-field="line.bo_value"
3232
/></td>
3333
<td class="text-right"><span
34-
t-field="line.uigd_qty"
34+
t-field="line.uninvoiced_goods_delivered_qty"
3535
/></td>
3636
<td class="text-right"><span
37-
t-field="line.uigd_value"
37+
t-field="line.uninvoiced_goods_delivered_value"
3838
/></td>
3939
<td><span t-field="line.last_date_delivered" /></td>
4040
<td><span t-field="line.last_bill_date" /></td>

sale_backorder/tests/test_sale_backorder.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ def setUp(self):
1313
super(TestSaleBackorderCommon, self).setUp()
1414
self.SaleOrder = self.env["sale.order"]
1515
self.sobackorder_wiz = self.env["sobackorder.report.wizard"]
16-
self.fsm_per_order_1 = self.env["product.product"].create(
16+
self.product_obj = self.env["product.product"]
17+
self.fsm_per_order_1 = self.product_obj.create(
1718
{
1819
"name": "FSM Order per Sale Order #1",
1920
"categ_id": self.env.ref("product.product_category_3").id,
@@ -25,7 +26,7 @@ def setUp(self):
2526
"invoice_policy": "order",
2627
}
2728
)
28-
self.fsm_per_order_2 = self.env["product.product"].create(
29+
self.fsm_per_order_2 = self.product_obj.create(
2930
{
3031
"name": "FSM Order per Sale Order #1",
3132
"categ_id": self.env.ref("product.product_category_3").id,
@@ -78,7 +79,7 @@ def setUp(self):
7879
"product_uom": self.fsm_per_order_1.uom_id.id,
7980
"price_unit": self.fsm_per_order_1.list_price,
8081
"tax_id": False,
81-
"uigd_value": 1.0,
82+
"uninvoiced_goods_delivered_value": 1.0,
8283
"bo_value": 1.0,
8384
"bo_qty": 1.0,
8485
},
@@ -93,7 +94,7 @@ def setUp(self):
9394
"product_uom": self.fsm_per_order_2.uom_id.id,
9495
"price_unit": self.fsm_per_order_2.list_price,
9596
"tax_id": False,
96-
"uigd_value": 1.0,
97+
"uninvoiced_goods_delivered_value": 1.0,
9798
"bo_value": 1.0,
9899
"bo_qty": 1.0,
99100
"last_date_delivered": datetime.now() + rdelta(days=15),
@@ -117,16 +118,14 @@ def test_sale_order(self):
117118

118119
def test_sale_order_order_line(self):
119120
self.sale_order_1.action_confirm()
120-
self.context = {
121-
"active_model": "sale.order",
122-
"active_ids": [self.sale_order_1.id],
123-
"active_id": self.sale_order_1.id,
124-
"default_journal_id": self.default_journal_sale.id,
125-
}
126-
127121
downpayment = (
128122
self.env["sale.advance.payment.inv"]
129-
.with_context(self.context)
123+
.with_context(
124+
active_model="sale.order",
125+
active_ids=self.sale_order_1.ids,
126+
active_id=self.sale_order_1.id,
127+
default_journal_id=self.default_journal_sale.id,
128+
)
130129
.create(
131130
{
132131
"advance_payment_method": "fixed",
@@ -156,7 +155,11 @@ def test_sale_order_line_method(self):
156155
self.invoice.action_reverse()
157156
move_reversal = (
158157
self.env["account.move.reversal"]
159-
.with_context(active_model="account.move", active_ids=self.invoice.ids)
158+
.with_context(
159+
active_model="account.move",
160+
active_ids=self.invoice.ids,
161+
default_journal_id=self.default_journal_sale.id,
162+
)
160163
.create(
161164
{
162165
"date": datetime.today(),

sale_backorder/views/sale_view.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
21
<odoo>
32

43
<record id="sale_order_form_backorder" model="ir.ui.view">
@@ -7,10 +6,14 @@
76
<field name="inherit_id" ref="sale.view_order_form" />
87
<field name="arch" type="xml">
98
<xpath expr="//field[@name='partner_shipping_id']" position="after">
10-
<field name="uigd_value" readonly='1' />
9+
<field name="uninvoiced_goods_delivered_value" readonly='1' />
1110
<field name="bo_value" readonly='1' />
12-
<field name="last_bill_date" readonly='1' />
13-
<field name="last_date_delivered" readonly='1' />
11+
<field name="last_bill_date" readonly='1' string="Last Bill Date" />
12+
<field
13+
name="last_date_delivered"
14+
readonly='1'
15+
string="Last Date Delivered"
16+
/>
1417
</xpath>
1518
</field>
1619
</record>

sale_backorder/views/so_backorder_view.xml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
21
<odoo>
32

43
<record id="so_backorder_tree_view" model="ir.ui.view">
@@ -10,10 +9,10 @@
109
<field name="name" />
1110
<field name="bo_qty" />
1211
<field name="bo_value" />
13-
<field name="uigd_qty" />
14-
<field name="uigd_value" />
15-
<field name="last_date_delivered" />
16-
<field name="last_bill_date" />
12+
<field name="uninvoiced_goods_delivered_qty" />
13+
<field name="uninvoiced_goods_delivered_value" />
14+
<field name="last_date_delivered" string="Last Date Delivered" />
15+
<field name="last_bill_date" string="Last Bill Date" />
1716
</tree>
1817
</field>
1918
</record>
@@ -26,7 +25,7 @@
2625
<field name="view_id" ref="sale_backorder.so_backorder_tree_view" />
2726
<field name="context">{'create': False, 'edit': False}</field>
2827
<field name="domain">['&amp;', ('product_type', '=', 'product'), '|',
29-
('bo_value', '!=', 0), ('uigd_value', '!=', 0)]
28+
('bo_value', '!=', 0), ('uninvoiced_goods_delivered_value', '!=', 0)]
3029
</field>
3130
</record>
3231

sale_backorder/wizard/so_backorder_wizard.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def action_print_report(self):
1515
("product_type", "=", "product"),
1616
"|",
1717
("bo_value", "!=", 0),
18-
("uigd_value", "!=", 0),
18+
("uninvoiced_goods_delivered_value", "!=", 0),
1919
]
2020
)
21-
return self.env.ref("sale_backorder.action_so_backorder_report").report_action(
22-
data
23-
)
21+
return self.env.ref(
22+
"sale_backorder.action_so_backorder_report", raise_if_not_found=False
23+
).report_action(data)

0 commit comments

Comments
 (0)