Skip to content

Commit 60fb518

Browse files
committed
[IMP] Construction: Adding a cost automation
- Added "Automate Cost Update" checkbox in the "Vendor Bills" section of the "Purchase" tab in the product template view. - Implemented automation rule to update supplier info when a PO or Bill is saved with a different price for the same product, based on the checkbox being checked. task-4138749
1 parent eba84d6 commit 60fb518

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

construction/__manifest__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
focusing on accurate quoting, efficient planning, seamless execution, and excellent customer service, ...
88
""",
99
'depends': [
10+
'base_automation',
1011
'crm_enterprise',
1112
'documents',
1213
'helpdesk',
@@ -20,8 +21,13 @@
2021
'sale_margin',
2122
'sale_project_forecast',
2223
'sign',
24+
'web_studio',
2325
],
2426
'data': [
27+
'data/base_automation.xml',
28+
'data/ir_action_server.xml',
29+
'data/ir_model_fields.xml',
30+
'data/ir_ui_view.xml',
2531
'data/account_analytic_account.xml',
2632
'data/documents_folder.xml',
2733
'data/res_config_settings.xml',

construction/data/base_automation.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<odoo>
3+
<record id="base_automation_1" model="base.automation">
4+
<field name="name">Automate Supplier Info</field>
5+
<field name="model_id" ref="purchase.model_purchase_order"/>
6+
<field name="trigger">on_create_or_write</field>
7+
</record>
8+
</odoo>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<odoo>
3+
<record id="automate_sipplier_info" model="ir.actions.server">
4+
<field name="name">Automate the supplier info cost</field>
5+
<field name="model_id" ref="purchase.model_purchase_order"/>
6+
<field name="base_automation_id" ref="base_automation_1"/>
7+
<field name="filter_domain">["&amp;", ("state", "=", "purchase"), ("state", "=", "done")]</field>
8+
<field name="state">code</field>
9+
<field name="code"><![CDATA[
10+
for line in record.order_line:
11+
product = line.product_id
12+
if product.categ_id.x_automate_cost_update:
13+
supplier_info = env['product.supplierinfo'].search([
14+
('product_tmpl_id', '=', product.product_tmpl_id.id),
15+
('partner_id', '=', record.partner_id.id)
16+
], limit=1)
17+
18+
if supplier_info and float_compare(supplier_info.price, line.price_unit, precision_digits=2) != 0:
19+
supplier_info.write({
20+
'min_qty': line.product_qty,
21+
'price': line.price_unit,
22+
})
23+
product.write({'standard_price': line.price_unit})
24+
]]></field>
25+
</record>
26+
</odoo>

construction/data/ir_model_fields.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<odoo>
3+
<record id="x_automate_cost_update" model="ir.model.fields">
4+
<field name="name">x_automate_cost_update</field>
5+
<field name="ttype">boolean</field>
6+
<field name="model_id" ref="product.model_product_category"/>
7+
<field name="field_description">Automate Cost Update</field>
8+
</record>
9+
</odoo>

construction/data/ir_ui_view.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<odoo>
3+
<record id="product_category_form_view" model="ir.ui.view">
4+
<field name="name">product.category.form customization</field>
5+
<field name="inherit_id" ref="product.product_category_form_view"/>
6+
<field name="mode">extension</field>
7+
<field name="model">product.category</field>
8+
<field name="active" eval="True"/>
9+
<field name="priority">160</field>
10+
<field name="type">form</field>
11+
<field name="arch" type="xml">
12+
<xpath expr="//field[@name='property_cost_method']" position="after">
13+
<field name="x_automate_cost_update"/>
14+
</xpath>
15+
</field>
16+
</record>
17+
</odoo>

0 commit comments

Comments
 (0)