Skip to content

Commit 0ef65ea

Browse files
committed
Adaugă vizualizări pentru liniile de comandă în achiziții
--- Creată o nouă vedere pentru liniile de comandă din modelul `purchase.order` și adăugată logica pentru gestionarea acestora în XLS. Actualizat fișierul manifest pentru a include noile vizualizări și implementări, îmbunătățind experiența de utilizare și procesarea comenzilor.
1 parent ada4133 commit 0ef65ea

File tree

4 files changed

+140
-1
lines changed

4 files changed

+140
-1
lines changed

deltatech_purchase_xls/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"wizard/import_purchase_line_view.xml",
1616
"wizard/export_purchase_line_view.xml",
1717
"security/ir.model.access.csv",
18+
"views/purchase_order_view.xml",
1819
],
1920
"images": ["static/description/main_screenshot.png"],
2021
"installable": True,
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
# © 2015-220 Deltatech
1+
# © 2025 Deltatech
22
# Dorin Hongu <dhongu(@)gmail(.)com
33
# See README.rst file on addons root folder for license details
4+
5+
from . import purchase_order
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# © 2025 Deltatech
2+
# Dorin Hongu <dhongu(@)gmail(.)com
3+
# See README.rst file on addons root folder for license details
4+
5+
6+
from odoo import api, models
7+
8+
9+
class PurchaseOrder(models.Model):
10+
_inherit = "purchase.order"
11+
12+
def show_order_lines(self):
13+
"""Override to show order lines in the XLS report."""
14+
self.ensure_one()
15+
16+
tree_view_id = self.env.ref("deltatech_purchase_xls.purchase_order_line_tree").id
17+
return {
18+
"type": "ir.actions.act_window",
19+
"name": "Purchase Order Lines",
20+
"res_model": "purchase.order.line",
21+
"view_mode": "tree,form",
22+
"views": [(tree_view_id, "tree")],
23+
"domain": [("order_id", "=", self.id)],
24+
"context": {"default_order_id": self.id, "create": True, "edit": True},
25+
}
26+
27+
28+
class PurchaseOrderLine(models.Model):
29+
_inherit = "purchase.order.line"
30+
31+
def _parse_import_data(self, data, import_fields, options):
32+
return super()._parse_import_data(data, import_fields, options)
33+
34+
35+
# def _load_records(self, data_list, update=False):
36+
# order = self.env["purchase.order"]
37+
# order_id = self.env.context.get("default_order_id", False) or self.env.context.get("active_id", False)
38+
# if order_id:
39+
# order = self.env["purchase.order"].browse(order_id)
40+
# if order:
41+
#
42+
# for data in data_list:
43+
#
44+
# product_id = data["values"].get("product_id", "")
45+
#
46+
#
47+
# line = order.order_line.filtered(lambda l: l.product_id.id == product_id)
48+
# if line:
49+
# data["values"]["id"] = str(line[0].id)
50+
#
51+
#
52+
#
53+
# return super()._load_records(data_list, update)
54+
55+
56+
57+
@api.model
58+
def load(self, fields, data):
59+
order = self.env["purchase.order"]
60+
order_id = self.env.context.get("default_order_id", False) or self.env.context.get("active_id", False)
61+
if order_id:
62+
order = self.env["purchase.order"].browse(order_id)
63+
64+
if not order:
65+
order_index = fields.index.get("order_id", False)
66+
if order_index:
67+
order_id = data[0][order_index]
68+
order = self.env["purchase.order"].browse(order_id)
69+
70+
71+
72+
if order:
73+
74+
product_index = fields.index("product_id") if "product_id" in fields else -1
75+
fields.append(".id")
76+
index_id = fields.index(".id")
77+
for record in data:
78+
record.append("")
79+
80+
if product_index != -1:
81+
for record in data:
82+
product_name = record[product_index]
83+
product = self.env["product.product"]
84+
# extrage codul din numele produsului care este intre paranteze []
85+
if "[" in product_name and "]" in product_name:
86+
product_code = product_name.split("[")[-1].split("]")[0].strip()
87+
product = self.env["product.product"].search([('default_code', '=', product_code)], limit=1)
88+
if not product:
89+
product_name = product_name.split("[")[0].strip()
90+
product = self.env["product.product"].search([('name', '=', product_name)], limit=1)
91+
92+
if not product:
93+
data.remove(record)
94+
continue
95+
if product:
96+
line = order.order_line.filtered(lambda l: l.product_id.id == product.id)
97+
if line:
98+
record[index_id] = str(line.id)
99+
else:
100+
data.remove(record)
101+
102+
103+
return super().load(fields, data)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo>
3+
<record id="purchase_order_form" model="ir.ui.view">
4+
<field name="name">purchase.order.form</field>
5+
<field name="model">purchase.order</field>
6+
<field name="inherit_id" ref="purchase.purchase_order_form" />
7+
<field name="arch" type="xml">
8+
<div name="button_box" position="inside">
9+
<button name="show_order_lines" type="object" class="oe_stat_button" icon="fa-list-ul">
10+
<span>Order lines</span>
11+
</button>
12+
</div>
13+
14+
</field>
15+
</record>
16+
17+
18+
<record id="purchase_order_line_tree" model="ir.ui.view">
19+
<field name="name">purchase.order.line.tree</field>
20+
<field name="model">purchase.order.line</field>
21+
22+
<field name="arch" type="xml">
23+
<tree>
24+
<field name="order_id" widget="many2one" />
25+
<field name="product_id" />
26+
<field name="product_uom_qty" />
27+
<field name="price_unit" />
28+
</tree>
29+
</field>
30+
</record>
31+
32+
33+
</odoo>

0 commit comments

Comments
 (0)