purchase_usability: warning when price and/or delay is auto-updated following a qty change
It is similar to the feature present in sale_usability when the qty is updated and the price unit changes
This commit is contained in:
@@ -2,8 +2,9 @@
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo.tools.misc import formatLang
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.tools.misc import format_datetime, format_amount
|
||||
from odoo.tools import float_compare
|
||||
|
||||
|
||||
class PurchaseOrder(models.Model):
|
||||
@@ -25,7 +26,7 @@ class PurchaseOrder(models.Model):
|
||||
order.delivery_partner_id = order.dest_address_id
|
||||
|
||||
# Re-write native name_get() to use amount_untaxed instead of amount_total
|
||||
@api.depends('name', 'partner_ref')
|
||||
@api.depends('name', 'partner_ref', 'amount_untaxed')
|
||||
def name_get(self):
|
||||
result = []
|
||||
for po in self:
|
||||
@@ -33,8 +34,8 @@ class PurchaseOrder(models.Model):
|
||||
if po.partner_ref:
|
||||
name += ' (' + po.partner_ref + ')'
|
||||
if self.env.context.get('show_total_amount') and po.amount_untaxed:
|
||||
name += ': ' + formatLang(
|
||||
self.env, po.amount_untaxed, currency_obj=po.currency_id)
|
||||
name += ': ' + format_amount(
|
||||
self.env, po.amount_untaxed, po.currency_id)
|
||||
result.append((po.id, name))
|
||||
return result
|
||||
|
||||
@@ -72,7 +73,8 @@ class PurchaseOrderLine(models.Model):
|
||||
_inherit = 'purchase.order.line'
|
||||
|
||||
# for optional display in tree view
|
||||
product_barcode = fields.Char(related='product_id.barcode', string="Product Barcode")
|
||||
product_barcode = fields.Char(
|
||||
related='product_id.barcode', string="Product Barcode")
|
||||
product_supplier_code = fields.Char(
|
||||
compute='_compute_product_supplier_code', string='Vendor Product Code')
|
||||
|
||||
@@ -98,3 +100,41 @@ class PurchaseOrderLine(models.Model):
|
||||
if no_product_code_param and no_product_code_param == 'True':
|
||||
product_lang = product_lang.with_context(display_default_code=False)
|
||||
return super()._get_product_purchase_description(product_lang)
|
||||
|
||||
@api.onchange('product_qty', 'product_uom')
|
||||
def _onchange_quantity(self):
|
||||
# When the user has manually set a price and/or planned_date
|
||||
# he is often upset when Odoo changes it when he changes the qty
|
||||
# So we add a warning...
|
||||
res = {}
|
||||
old_price = self.price_unit
|
||||
old_date_planned = self.date_planned
|
||||
super()._onchange_quantity()
|
||||
new_price = self.price_unit
|
||||
new_date_planned = self.date_planned
|
||||
prec = self.env['decimal.precision'].precision_get('Product Price')
|
||||
price_compare = float_compare(old_price, new_price, precision_digits=prec)
|
||||
if price_compare or old_date_planned != new_date_planned:
|
||||
res['warning'] = {
|
||||
'title': _('Updates'),
|
||||
'message': _(
|
||||
"Due to the update of the ordered quantity on line '%s', "
|
||||
"the following data has been updated using the supplier info "
|
||||
"of the product:"
|
||||
) % self.name
|
||||
}
|
||||
if price_compare:
|
||||
res['warning']['message'] += _(
|
||||
"\nOld price: %s\nNew price: %s") % (
|
||||
format_amount(
|
||||
self.env, old_price, self.order_id.currency_id),
|
||||
format_amount(
|
||||
self.env, new_price, self.order_id.currency_id))
|
||||
|
||||
if old_date_planned != new_date_planned:
|
||||
res['warning']['message'] += _(
|
||||
"\nOld delivery date: %s\nNew delivery date: %s") % (
|
||||
format_datetime(self.env, old_date_planned),
|
||||
format_datetime(self.env, new_date_planned),
|
||||
)
|
||||
return res
|
||||
|
||||
Reference in New Issue
Block a user