Skip to content

Commit b836527

Browse files
committed
Merge PR #1281 into 18.0
Signed-off-by pedrobaeza
2 parents f302a0c + 52cce0a commit b836527

File tree

3 files changed

+91
-11
lines changed

3 files changed

+91
-11
lines changed

product_contract/__manifest__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,14 @@
2222
"application": False,
2323
"external_dependencies": {"python": ["python-dateutil"]},
2424
"maintainers": ["sbejaoui"],
25-
"assets": {"web.assets_backend": ["product_contract/static/src/js/*"]},
25+
"assets": {
26+
"web.assets_backend": [
27+
"product_contract/static/src/js/*",
28+
(
29+
"after",
30+
"sale/static/src/xml/sale_product_field.xml",
31+
"product_contract/static/src/xml/*",
32+
),
33+
]
34+
},
2635
}

product_contract/static/src/js/sale_product_field.esm.js

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,68 @@
1-
import {SaleOrderLineProductField} from "@sale/js/sale_product_field";
21
import {patch} from "@web/core/utils/patch";
2+
import {SaleOrderLineProductField} from "@sale/js/sale_product_field";
33

44
patch(SaleOrderLineProductField.prototype, {
5+
setup() {
6+
super.setup(...arguments);
7+
this.lastContractData = false;
8+
},
9+
10+
get extraLines() {
11+
var res = super.extraLines;
12+
if (
13+
this.props.record.data.is_contract &&
14+
this.props.record.data.product_contract_description
15+
) {
16+
for (var val of this.props.record.data.product_contract_description.split(
17+
"||"
18+
)) {
19+
res.push(val);
20+
}
21+
}
22+
return res;
23+
},
24+
525
async _onProductUpdate() {
626
super._onProductUpdate(...arguments);
727
if (this.props.record.data.is_contract) {
828
this._openContractConfigurator(true);
929
}
1030
},
1131

12-
_editLineConfiguration() {
13-
super._editLineConfiguration(...arguments);
32+
_editProductConfiguration() {
33+
if (
34+
this.props.record.data.is_configurable_product &&
35+
this.props.record.data.is_contract
36+
) {
37+
this.lastContractData = this.contractData;
38+
}
39+
super._editProductConfiguration(...arguments);
40+
},
41+
42+
onEditContractConfiguration() {
1443
if (this.props.record.data.is_contract) {
1544
this._openContractConfigurator();
1645
}
1746
},
1847

19-
get isConfigurableLine() {
20-
return super.isConfigurableLine || this.props.record.data.is_contract;
48+
get isConfigurableContract() {
49+
return this.props.record.data.is_contract;
2150
},
2251

23-
_getContractConfiguratorContext() {
52+
get contractContext() {
2453
return {
2554
active_model: this.props.record.resModel,
2655
active_id: this.props.record.resId,
2756
default_product_id: this.props.record.data.product_id[0],
2857
default_partner_id: this.props.record.model.root.data.partner_id[0],
2958
default_company_id: this.props.record.model.root.data.company_id[0],
3059
default_recurrence_number: this.props.record.data.recurrence_number,
31-
default_recurring_interval: this.props.record.data.recurring_interval,
3260
default_recurring_rule_type: this.props.record.data.recurring_rule_type,
33-
default_recurrence_interval: this.props.record.data.recurrence_interval,
3461
default_recurring_invoicing_type:
3562
this.props.record.data.recurring_invoicing_type,
3663
default_product_uom_qty: this.props.record.data.product_uom_qty,
3764
default_contract_id: this.props.record.data.contract_id[0],
65+
default_recurring_interval: this.props.record.data.recurring_interval,
3866
default_date_start: this.props.record.data.date_start,
3967
default_date_end: this.props.record.data.date_end,
4068
default_is_auto_renew: this.props.record.data.is_auto_renew,
@@ -45,13 +73,36 @@ patch(SaleOrderLineProductField.prototype, {
4573
};
4674
},
4775

76+
get contractData() {
77+
return {
78+
product_id: this.props.record.data.product_id,
79+
product_uom_qty: this.props.record.data.product_uom_qty,
80+
contract_id: this.props.record.data.contract_id,
81+
recurring_interval: this.props.record.data.recurring_interval,
82+
date_start: this.props.record.data.date_start,
83+
date_end: this.props.record.data.date_end,
84+
is_auto_renew: this.props.record.data.is_auto_renew,
85+
auto_renew_interval: this.props.record.data.auto_renew_interval,
86+
auto_renew_rule_type: this.props.record.data.auto_renew_rule_type,
87+
};
88+
},
89+
4890
async _openContractConfigurator(isNew = false) {
49-
const actionContext = this._getContractConfiguratorContext();
91+
if (this.lastContractData) {
92+
const changes = Object.assign({}, this.lastContractData);
93+
this.lastContractData = false;
94+
return this.props.record._update(changes, {
95+
withoutOnchange: true,
96+
});
97+
}
98+
const actionContext = this.contractContext;
5099
this.action.doAction("product_contract.product_contract_configurator_action", {
51100
additionalContext: actionContext,
52101
onClose: async (closeInfo) => {
53102
if (closeInfo && !closeInfo.special) {
54-
this.props.record.update(closeInfo.productContractConfiguration);
103+
this.props.record._update(closeInfo.productContractConfiguration, {
104+
withoutOnchange: true,
105+
});
55106
} else if (isNew) {
56107
this.props.record.update({
57108
[this.props.name]: undefined,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
4+
<t t-inherit="sale.SaleProductField" t-inherit-mode="extension">
5+
<xpath expr="//button[@t-if='hasExternalButton']" position="before">
6+
<t t-if="isConfigurableContract">
7+
<button
8+
type="button"
9+
class="btn btn-secondary fa fa-pencil-square-o"
10+
tabindex="-1"
11+
draggable="false"
12+
aria-label="Configure contract"
13+
data-tooltip="Configure contract"
14+
t-on-click="onEditContractConfiguration"
15+
/>
16+
</t>
17+
</xpath>
18+
</t>
19+
20+
</templates>

0 commit comments

Comments
 (0)