Skip to content

Commit

Permalink
[IMP] product_contract: Add contract configurator instead of making t…
Browse files Browse the repository at this point in the history
…ree not editable

Before this changes, when trying to edit a line of sale order, it was
opening the form of the line. But following the way to work of odoo
with sale event, we have make a new contract configurator that will
be opened when selecting a product of type contract.
  • Loading branch information
CarlosRoca13 committed Aug 26, 2024
1 parent 7f7d947 commit 88d2cb9
Show file tree
Hide file tree
Showing 10 changed files with 367 additions and 22 deletions.
1 change: 1 addition & 0 deletions product_contract/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
from . import wizards
3 changes: 3 additions & 0 deletions product_contract/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
"website": "https://github.com/OCA/contract",
"depends": ["product", "contract", "sale"],
"data": [
"security/ir.model.access.csv",
"wizards/res_config_settings.xml",
"views/contract.xml",
"views/product_template.xml",
"views/sale_order.xml",
"wizards/product_contract_configurator_views.xml",
],
"installable": True,
"application": False,
"external_dependencies": {"python": ["dateutil"]},
"maintainers": ["sbejaoui"],
"assets": {"web.assets_backend": ["product_contract/static/src/js/*"]},
}
2 changes: 2 additions & 0 deletions product_contract/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_product_contract_configurator,access.product.contract.configurator,model_product_contract_configurator,sales_team.group_sale_salesman,1,1,1,0
11 changes: 7 additions & 4 deletions product_contract/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -431,7 +432,9 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/** @odoo-module **/

import {formView} from "@web/views/form/form_view";
import {registry} from "@web/core/registry";
import {useService} from "@web/core/utils/hooks";

export class ProductContractConfiguratorController extends formView.Controller {
setup() {
super.setup();
this.action = useService("action");
}

async onRecordSaved(record) {
await super.onRecordSaved(...arguments);
const {
product_uom_qty,
contract_id,
recurring_rule_type,
recurring_invoicing_type,
date_start,
date_end,
contract_line_id,
is_auto_renew,
auto_renew_interval,
auto_renew_rule_type,
} = record.data;
return this.action.doAction({
type: "ir.actions.act_window_close",
infos: {
productContractConfiguration: {
product_uom_qty,
contract_id,
recurring_rule_type,
recurring_invoicing_type,
date_start,
date_end,
contract_line_id,
is_auto_renew,
auto_renew_interval,
auto_renew_rule_type,
},
},
});
}
}

registry.category("views").add("product_contract_configurator_form", {
...formView,
Controller: ProductContractConfiguratorController,
});
54 changes: 54 additions & 0 deletions product_contract/static/src/js/sale_product_field.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/** @odoo-module **/

import {SaleOrderLineProductField} from "@sale/js/sale_product_field";
import {patch} from "@web/core/utils/patch";

patch(SaleOrderLineProductField.prototype, {
async _onProductUpdate() {
super._onProductUpdate(...arguments);
if (this.props.record.data.is_contract) {
this._openContractConfigurator(true);
}
},

_editLineConfiguration() {
super._editLineConfiguration(...arguments);
if (this.props.record.data.is_contract) {
this._openContractConfigurator();
}
},

get isConfigurableLine() {
return super.isConfigurableLine || this.props.record.data.is_contract;
},

async _openContractConfigurator(isNew = false) {
const actionContext = {
default_product_id: this.props.record.data.product_id[0],
default_partner_id: this.props.record.model.root.data.partner_id[0],
default_company_id: this.props.record.model.root.data.company_id[0],
default_product_uom_qty: this.props.record.data.product_uom_qty,
default_contract_id: this.props.record.data.contract_id[0],
default_recurring_rule_type: this.props.record.data.recurring_rule_type,
default_recurring_invoicing_type:
this.props.record.data.recurring_invoicing_type,
default_date_start: this.props.record.data.date_start,
default_date_end: this.props.record.data.date_end,
default_is_auto_renew: this.props.record.data.is_auto_renew,
default_auto_renew_interval: this.props.record.data.auto_renew_interval,
default_auto_renew_rule_type: this.props.record.data.auto_renew_rule_type,
};
this.action.doAction("product_contract.product_contract_configurator_action", {
additionalContext: actionContext,
onClose: async (closeInfo) => {
if (closeInfo && !closeInfo.special) {
this.props.record.update(closeInfo.productContractConfiguration);
} else if (isNew) {
this.props.record.update({
[this.props.name]: undefined,
});
}
},
});
},
});
62 changes: 44 additions & 18 deletions product_contract/views/sale_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
<field
name="contract_id"
options='{"no_create": True}'
invisible="is_contract == False"
invisible="not is_contract"
domain="['|',('contract_template_id','=',contract_template_id), ('contract_template_id','=',False), ('partner_id','=',parent.partner_id), ('is_terminated','=',False),
]"
/>
<field
name="contract_line_id"
invible="is_contract == False"
invisible="not is_contract"
domain="[('contract_id','=',contract_id)]"
/>
</xpath>
Expand All @@ -59,37 +59,37 @@
<separator
colspan="4"
string="Recurrence Invoicing"
invisible="is_contract == False"
invisible="not is_contract"
/>
<group invisible="is_contract == False">
<group invisible="not is_contract">
<field name="recurring_rule_type" />
</group>
<group invisible="is_contract == False">
<group invisible="not is_contract">
<field name="recurring_invoicing_type" />
</group>
<group invisible="is_contract == False">
<field name="date_start" required="is_contract == True" />
<group invisible="not is_contract">
<field name="date_start" required="is_contract" />
</group>
<group invisible="is_contract == False">
<field name="date_end" required="is_contract == True" />
<group invisible="not is_contract">
<field name="date_end" required="is_contract" />
</group>
<group invisible="is_contract == False">
<group invisible="not is_contract">
<field name="is_auto_renew" />
</group>
<group invisible="is_auto_renew == False">
<group invisible="not is_auto_renew">
<label for="auto_renew_interval" />
<div>
<field
name="auto_renew_interval"
class="oe_inline"
nolabel="1"
required="is_auto_renew == True"
required="is_auto_renew"
/>
<field
name="auto_renew_rule_type"
class="oe_inline"
nolabel="1"
required="is_auto_renew == True"
required="is_auto_renew"
/>
</div>
</group>
Expand All @@ -98,15 +98,41 @@
expr="//field[@name='order_line']/tree//field[@name='price_total']"
position="after"
>
<field name="contract_template_id" column_invisible="1" />
<field name="is_contract" column_invisible="1" />
<field
name="date_start"
column_invisible="parent.is_contract == False"
name="contract_id"
options='{"no_create": True}'
domain="['|',('contract_template_id','=',contract_template_id), ('contract_template_id','=',False), ('partner_id','=',parent.partner_id), ('is_terminated','=',False),
]"
optional="hide"
/>
<field
name="contract_line_id"
domain="[('contract_id','=',contract_id)]"
optional="hide"
/>
<field name="recurring_rule_type" optional="hide" />
<field name="recurring_invoicing_type" optional="hide" />
<field name="date_start" optional="hide" required="is_contract" />
<field name="date_end" required="is_contract" optional="hide" />
<field name="is_auto_renew" optional="hide" />
<field
name="auto_renew_interval"
class="oe_inline"
nolabel="1"
required="is_auto_renew"
optional="hide"
/>
<field
name="auto_renew_rule_type"
class="oe_inline"
nolabel="1"
required="is_auto_renew"
optional="hide"
/>
<field name="date_end" column_invisible="parent.is_contract == False" />
</xpath>
<xpath expr="//field[@name='order_line']/tree" position="attributes">
<attribute name="editable" />
</xpath>
</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions product_contract/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import product_contract_configurator
Loading

0 comments on commit 88d2cb9

Please sign in to comment.