虽然我们向客户报价,但不允许用户以低于产品销售价格的价格报价。我们怎样才能做到这一点?请帮我。我正在使用v7 ..提前致谢
答案 0 :(得分:1)
在视图xml
中调用字段price_unit
的函数
<xpath expr="//field[@name='price_unit']" position="attributes">
<attribute name="on_change">check_margin(product_id,price_unit)</attribute>
</xpath>
并在类中定义处理它的函数。
def check_margin(self, cr, uid, ids, product_id, unit_price, context=None):
res = {}
warning = {}
sale_price = None
if product_id:
sale_price = self.pool.get('product.product').browse(cr, uid,product_id).list_price
if unit_price is None:
pass
elif unit_price < sale_price:
warning = {
'title': _("Warning"),
'message': _('Unit price given, is less than the sales price of the selected product. Please change (or contact your sales manager to change) the sales price of the selected product.'),
}
res = {'value': {'price_unit':sale_price}}
elif unit_price >= sale_price:
res = {'value': {'price_unit':unit_price}}
pass
return {'value': res.get('value'), 'warning':warning}