Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] Construction: Adding a cost automation #226

Open
wants to merge 1 commit into
base: saas-17.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions construction/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
focusing on accurate quoting, efficient planning, seamless execution, and excellent customer service, ...
""",
'depends': [
'base_automation',
'crm_enterprise',
'documents',
'helpdesk',
Expand All @@ -20,8 +21,13 @@
'sale_margin',
'sale_project_forecast',
'sign',
'web_studio',
],
'data': [
'data/base_automation.xml',
'data/ir_action_server.xml',
'data/ir_model_fields.xml',
'data/ir_ui_view.xml',
'data/account_analytic_account.xml',
'data/documents_folder.xml',
'data/res_config_settings.xml',
Expand Down
19 changes: 19 additions & 0 deletions construction/data/base_automation.xml
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>
48 changes: 48 additions & 0 deletions construction/data/ir_action_server.xml
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>
9 changes: 9 additions & 0 deletions construction/data/ir_model_fields.xml
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>
17 changes: 17 additions & 0 deletions construction/data/ir_ui_view.xml
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>