summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJigar Vaghela <jva@odoo.com>2019-03-01 13:13:27 +0000
committerDamien Bouvy <dbo@odoo.com>2019-12-13 14:09:36 +0000
commitff195561216d4e98ff1b7aaf4a5bab49d4e448e5 (patch)
tree92318b27b9e675cac80afb74849d74df89625adf
parent39979b75580d8874a3ef9d1e93a122e40545a1d2 (diff)
[IMP] sale: change the pricelist in the quotation its update prices of product.
purpose of this commit is when the pricelist is chnaged and some products alredy added to the sale order, display a button "recompute price" that throws a confirmation model asking for recompute the price of the so line task: 1947320 Closes: #31535 Co-authored-by: Mitali Patel <mpa@odoo.com>
-rw-r--r--addons/sale/models/sale.py30
-rw-r--r--addons/sale/views/sale_views.xml12
-rw-r--r--addons/sale_management/models/sale_order.py7
3 files changed, 47 insertions, 2 deletions
diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py
index c49c864e772..a93875f08d9 100644
--- a/addons/sale/models/sale.py
+++ b/addons/sale/models/sale.py
@@ -162,7 +162,7 @@ class SaleOrder(models.Model):
pricelist_id = fields.Many2one(
'product.pricelist', string='Pricelist', check_company=True, # Unrequired company
required=True, readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]},
- domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",
+ domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", tracking=1,
help="If you change the pricelist, only newly added lines will be affected.")
currency_id = fields.Many2one("res.currency", related='pricelist_id.currency_id', string="Currency", readonly=True, required=True)
analytic_account_id = fields.Many2one(
@@ -225,6 +225,9 @@ class SaleOrder(models.Model):
string='Transactions', copy=False, readonly=True)
authorized_transaction_ids = fields.Many2many('payment.transaction', compute='_compute_authorized_transaction_ids',
string='Authorized Transactions', copy=False, readonly=True)
+ show_update_pricelist = fields.Boolean(string='Has Pricelist Changed',
+ help="Technical Field, True if the pricelist was changed;\n"
+ " this will then display a recomputation button")
_sql_constraints = [
('date_order_conditional_required', "CHECK( (state IN ('sale', 'done') AND date_order IS NOT NULL) OR state NOT IN ('sale', 'done') )", "A confirmed sales order requires a confirmation date."),
@@ -402,6 +405,31 @@ class SaleOrder(models.Model):
}
}
+ @api.onchange('pricelist_id')
+ def _onchange_pricelist_id(self):
+ if self.order_line and self.pricelist_id and self._origin.pricelist_id and self._origin.pricelist_id != self.pricelist_id:
+ self.show_update_pricelist = True
+ else:
+ self.show_update_pricelist = False
+
+ def update_prices(self):
+ self.ensure_one()
+ lines_to_update = []
+ for line in self.order_line.filtered(lambda line: not line.display_type):
+ product = line.product_id.with_context(
+ partner=self.partner_id,
+ quantity=line.product_uom_qty,
+ date=self.date_order,
+ pricelist=self.pricelist_id.id,
+ uom=line.product_uom.id
+ )
+ price_unit = self.env['account.tax']._fix_tax_included_price_company(
+ line._get_display_price(product), line.product_id.taxes_id, line.tax_id, line.company_id)
+ lines_to_update.append((1, line.id, {'price_unit': price_unit}))
+ self.update({'order_line': lines_to_update})
+ self.show_update_pricelist = False
+ self.message_post(body=_("Product prices have been recomputed according to pricelist <b>%s<b> ") % self.pricelist_id.display_name)
+
@api.model
def create(self, vals):
if vals.get('name', _('New')) == _('New'):
diff --git a/addons/sale/views/sale_views.xml b/addons/sale/views/sale_views.xml
index 611a1f2c2a5..05208ef31d2 100644
--- a/addons/sale/views/sale_views.xml
+++ b/addons/sale/views/sale_views.xml
@@ -320,7 +320,17 @@
<label for="date_order" string="Order Date"/>
</div>
<field name="date_order" attrs="{'required': [('state', 'in', ['sale', 'done'])], 'invisible': [('state', 'in', ['draft', 'sent'])]}" nolabel="1"/>
- <field name="pricelist_id" groups="product.group_product_pricelist" options="{'no_open':True,'no_create': True}"/>
+ <field name="show_update_pricelist" invisible="1"/>
+ <label for="pricelist_id" groups="product.group_product_pricelist"/>
+ <div groups="product.group_product_pricelist" class="o_row">
+ <field name="pricelist_id" options="{'no_open':True,'no_create': True}"/>
+ <button name="update_prices" type="object"
+ string=" Update Prices"
+ help="Recompute all prices based on this pricelist"
+ class="btn-link mb-1 px-0" icon="fa-refresh"
+ confirm="This will update all unit prices based on the currently set pricelist."
+ attrs="{'invisible': ['|', ('show_update_pricelist', '=', False), ('state', 'in', ['sale', 'done','cancel'])]}"/>
+ </div>
<field name="currency_id" invisible="1"/>
<field name="payment_term_id" options="{'no_open':True,'no_create': True}"/>
</group>
diff --git a/addons/sale_management/models/sale_order.py b/addons/sale_management/models/sale_order.py
index c4a2a54af12..90f91563b46 100644
--- a/addons/sale_management/models/sale_order.py
+++ b/addons/sale_management/models/sale_order.py
@@ -62,6 +62,13 @@ class SaleOrder(models.Model):
'discount': option.discount,
}
+ def update_prices(self):
+ self.ensure_one()
+ res = super().update_prices()
+ for line in self.sale_order_option_ids:
+ line.price_unit = self.pricelist_id.get_product_price(line.product_id, line.quantity, self.partner_id, uom_id=line.uom_id.id)
+ return res
+
@api.onchange('sale_order_template_id')
def onchange_sale_order_template_id(self):
if not self.sale_order_template_id: