[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>
This commit is contained in:
committed by
Damien Bouvy
co-authored by
Mitali Patel
parent
39979b7558
commit
ff19556121
@@ -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'):
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user