-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
Showing
5 changed files
with
99 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<odoo> | ||
<record id="base_automation_1" model="base.automation"> | ||
<field name="name">Automate Supplier Info</field> | ||
<field name="model_id" ref="purchase.model_purchase_order"/> | ||
<field name="trigger_field_ids" eval="[(6, 0, [ref('purchase.field_purchase_order__state')])]"/> | ||
<field name="trigger">on_state_set</field> | ||
<field name="trg_selection_field_id" ref="purchase.selection__purchase_order__state__purchase"/> | ||
<field name="filter_domain">[('state', '=', 'purchase')]</field> | ||
</record> | ||
<record id="base_automation_2" model="base.automation" context="{'studio': True}"> | ||
<field name="model_id" ref="account.model_account_move"/> | ||
<field name="trigger_field_ids" eval="[(6, 0, [ref('account.field_account_move__state')])]"/> | ||
<field name="trigger">on_state_set</field> | ||
<field name="trg_selection_field_id" ref="account.selection__account_move__state__posted"/> | ||
<field name="filter_domain">[('state', '=', 'posted')]</field> | ||
<field name="name">Automate Supplier Info</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<odoo> | ||
<record id="automate_sipplier_info" model="ir.actions.server"> | ||
<field name="name">Automate the supplier info cost</field> | ||
<field name="model_id" ref="purchase.model_purchase_order"/> | ||
<field name="base_automation_id" ref="base_automation_1"/> | ||
<field name="state">code</field> | ||
<field name="code"><![CDATA[ | ||
for line in record.order_line: | ||
product = line.product_id | ||
if product.categ_id.x_automate_cost_update: | ||
supplier_info = env['product.supplierinfo'].search([ | ||
('product_tmpl_id', '=', product.product_tmpl_id.id), | ||
('partner_id', '=', record.partner_id.id) | ||
], limit=1) | ||
if supplier_info and float_compare(supplier_info.price, line.price_unit, precision_digits=2) != 0: | ||
supplier_info.write({ | ||
'min_qty': line.product_qty, | ||
'price': line.price_unit, | ||
}) | ||
product.write({'standard_price': line.price_unit}) | ||
]]></field> | ||
</record> | ||
|
||
<record id="automate_sipplier_info_invoices" model="ir.actions.server"> | ||
<field name="name">Automate the supplier info cost Invoices</field> | ||
<field name="model_id" ref="account.model_account_move"/> | ||
<field name="base_automation_id" ref="base_automation_2"/> | ||
<field name="state">code</field> | ||
<field name="code"><![CDATA[ | ||
for line in record.invoice_line_ids: | ||
product = line.product_id | ||
if product.categ_id.x_automate_cost_update: | ||
supplier_info = env['product.supplierinfo'].search([ | ||
('product_tmpl_id', '=', product.product_tmpl_id.id), | ||
('partner_id', '=', record.partner_id.id) | ||
], limit=1) | ||
if supplier_info and float_compare(supplier_info.price, line.price_unit, precision_digits=2) != 0: | ||
supplier_info.write({ | ||
'min_qty': line.quantity, | ||
'price': line.price_unit, | ||
}) | ||
product.write({'standard_price': line.price_unit}) | ||
]]></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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<odoo> | ||
<record id="x_automate_cost_update" model="ir.model.fields"> | ||
<field name="name">x_automate_cost_update</field> | ||
<field name="ttype">boolean</field> | ||
<field name="model_id" ref="product.model_product_category"/> | ||
<field name="field_description">Automate Cost Update</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<odoo> | ||
<record id="product_category_form_view" model="ir.ui.view"> | ||
<field name="name">product.category.form customization</field> | ||
<field name="inherit_id" ref="product.product_category_form_view"/> | ||
<field name="mode">extension</field> | ||
<field name="model">product.category</field> | ||
<field name="active" eval="True"/> | ||
<field name="priority">160</field> | ||
<field name="type">form</field> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//field[@name='property_cost_method']" position="after"> | ||
<field name="x_automate_cost_update"/> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |