Skip to content

Commit

Permalink
[MIG] sale_order_line_price_history: Migration to 16.0
Browse files Browse the repository at this point in the history
Migrate the SaleOrderLinePriceHistoryWidget to PriceHistoryWidget using the new OWL 16
  • Loading branch information
Yadier-Tecnativa committed May 6, 2023
1 parent 85a0d69 commit ac70f63
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 74 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ env:
# See https://github.com/OCA/odoo-community.org/issues/37#issuecomment-470686449
parserOptions:
ecmaVersion: 2019
sourceType: module
allowImportExportEverywhere: true

overrides:
- files:
- "**/*.esm.js"
parserOptions:
sourceType: module
allowImportExportEverywhere: true

# Globals available in Odoo that shouldn't produce errorings
globals:
Expand Down
8 changes: 3 additions & 5 deletions sale_order_line_price_history/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Sale order line price history",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"category": "Sales Management",
"author": "Tecnativa," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sale-workflow",
Expand All @@ -15,10 +15,8 @@
],
"assets": {
"web.assets_backend": [
"sale_order_line_price_history/static/src/js/sale_line_price_history_widget.js",
],
"web.assets_qweb": [
"sale_order_line_price_history/static/src/xml/sale_line_price_history_widget.xml",
"sale_order_line_price_history/static/src/js/*.js",
"sale_order_line_price_history/static/src/xml/*.xml",
],
},
"installable": True,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,33 @@
/* Copyright 2021 Tecnativa - David Vidal
* License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
*/
odoo.define("sale_order_line_price_history.price_history_widget", function (require) {
"use strict";
/** @odoo-module **/
const {Component} = owl;
// Import the registry
import {registry} from "@web/core/registry";
import {standardFieldProps} from "@web/views/fields/standard_field_props";
import {useService} from "@web/core/utils/hooks";

var Widget = require("web.Widget");
var widget_registry = require("web.widget_registry");
export class PriceHistoryWidget extends Component {
setup() {
super.setup();
this.actionService = useService("action");
}

var SaleOrderLinePriceHistoryWidget = Widget.extend({
template: "sale_order_line_price_history.price_history_widget",
events: _.extend({}, Widget.prototype.events, {
"click .price_history": "_onClickButton",
}),

init: function (parent, params) {
this.data = params.data;
this._super(parent);
},

updateState: function (state) {
var candidate = state.data[this.getParent().currentRow];
if (candidate) {
this.data = candidate.data;
this.renderElement();
}
},

_onClickButton: function () {
// When it's a new line, we can't rely on a line id for the wizard, but
// we can provide the proper element to find the historic lines.
this.$el.find(".price_history").prop("special_click", true);
var additional_context = {};
if (this.data.id) {
additional_context = {active_id: this.data.id};
} else {
additional_context = {
default_partner_id: this.data.order_partner_id.res_id,
default_product_id: this.data.product_id.res_id,
};
viewPriceHistory() {
this.actionService.doAction(
"sale_order_line_price_history.sale_order_line_price_history_action",
{
additionalContext: {
default_product_id: this.props.record.data.product_id[0],
default_partner_id: this.props.record.data.order_partner_id[0],
default_active_id: this.props.value,
default_sale_order_line_id: this.props.value,
},
}
this.do_action(
"sale_order_line_price_history.sale_order_line_price_history_action",
{
additional_context: additional_context,
}
);
},
});
);
}
}

widget_registry.add(
"sale_line_price_history_widget",
SaleOrderLinePriceHistoryWidget
);
PriceHistoryWidget.template = "sale_order_line_price_history.price_history_widget";
PriceHistoryWidget.props = standardFieldProps;

return SaleOrderLinePriceHistoryWidget;
});
// Add the field to the correct category
registry.category("fields").add("sale_line_price_history_widget", PriceHistoryWidget);
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- Copyright 2021 Tecnativa - David Vidal
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -->
<templates>
<div t-name="sale_order_line_price_history.price_history_widget">
<t t-name="sale_order_line_price_history.price_history_widget" owl="1">
<div>
<a tabindex="0" class="fa fa-clock-o text-dark price_history" />
<a tabindex="0" t-on-click="viewPriceHistory" class="fa fa-history" />
</div>
</div>
</t>
</templates>
15 changes: 5 additions & 10 deletions sale_order_line_price_history/views/sale_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@
<field name="arch" type="xml">
<xpath expr="//field[@name='order_line']/tree">
<field name="order_partner_id" invisible="1" />
<widget
name="sale_line_price_history_widget"
width="20px"
attrs="{'invisible': [('id', '!=', False)]}"
/>
<button
name="%(sale_order_line_price_history_action)d"
type="action"
icon="fa-clock-o"
attrs="{'invisible': [('id', '=', False)]}"
<field
name="id"
string="Price History"
context="{'active_id': id, 'active_ids': [id]}"
widget="sale_line_price_history_widget"
/>
</xpath>
</field>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2019 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
from odoo.exceptions import ValidationError


class SaleOrderLinePriceHistory(models.TransientModel):
Expand Down Expand Up @@ -80,6 +81,7 @@ def _onchange_partner_id(self):
{
"sale_order_line_id": order_line.id,
"history_sale_order_line_id": self.sale_order_line_id.id,
"history_id": self.id,
},
)
)
Expand Down Expand Up @@ -131,5 +133,12 @@ def _prepare_set_price_history_vals(self):
return {"price_unit": self.price_unit, "discount": self.discount}

def action_set_price(self):
self.ensure_one()
self.history_sale_order_line_id.write(self._prepare_set_price_history_vals())
if self.history_sale_order_line_id and self.sale_order_line_id:
self.history_sale_order_line_id.write(
self._prepare_set_price_history_vals()
)
else:
raise ValidationError(
"Not found sale order line for %s %s"
% (self.history_sale_order_line_id, self.sale_order_line_id)
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<field name="include_commercial_partner" />
<field name="include_quotations" />
</group>
<group string="Sale history">
<field name="line_ids" nolabel="1" readonly="1">
<group string="Sale history" col="2">
<field name="line_ids" nolabel="1" readonly="1" colspan="2">
<form>
<div
class="oe_button_box"
Expand Down

0 comments on commit ac70f63

Please sign in to comment.