[FIX] margins in pricelists
bzr revid: fp@tinyerp.com-20120926082250-izv3jk874780htt8
This commit is contained in:
commit
859450d0c8
|
@ -394,6 +394,12 @@ class product_pricelist_item(osv.osv):
|
|||
return False
|
||||
return True
|
||||
|
||||
def _check_margin(self, cr, uid, ids, context=None):
|
||||
for item in self.browse(cr, uid, ids, context=context):
|
||||
if item.price_max_margin and item.price_min_margin and (item.price_min_margin > item.price_max_margin):
|
||||
return False
|
||||
return True
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Rule Name', size=64, help="Explicit rule name for this pricelist line."),
|
||||
'price_version_id': fields.many2one('product.pricelist.version', 'Price List Version', required=True, select=True, ondelete='cascade'),
|
||||
|
@ -401,13 +407,13 @@ class product_pricelist_item(osv.osv):
|
|||
'product_id': fields.many2one('product.product', 'Product', ondelete='cascade', help="Set a product if this rule only apply to one product. Keep empty for all products"),
|
||||
'categ_id': fields.many2one('product.category', 'Product Category', ondelete='cascade', help="Set a category of product if this rule only apply to products of a category and his children. Keep empty for all products"),
|
||||
|
||||
'min_quantity': fields.integer('Min. Quantity', required=True, help="The rule only applies if the partner buys/sells more than this quantity."),
|
||||
'min_quantity': fields.integer('Min. Quantity', required=True, help="The rule only applies if the partner buys/sells equal to or more than this quantity."),
|
||||
'sequence': fields.integer('Sequence', required=True, help="Gives the order in which the pricelist items will be checked. The evaluation gives highest priority to lowest sequence and stops as soon as a matching item is found."),
|
||||
'base': fields.selection(_price_field_get, 'Based on', required=True, size=-1, help="The mode for computing the price for this rule."),
|
||||
'base_pricelist_id': fields.many2one('product.pricelist', 'If Other Pricelist'),
|
||||
|
||||
'price_surcharge': fields.float('Price Surcharge',
|
||||
digits_compute= dp.get_precision('Product Price')),
|
||||
digits_compute= dp.get_precision('Product Price'), help='Specify the fixed amount to add or substract(if negative) to the amount calculated with the discount.'),
|
||||
'price_discount': fields.float('Price Discount', digits=(16,4)),
|
||||
'price_round': fields.float('Price Rounding',
|
||||
digits_compute= dp.get_precision('Product Price'),
|
||||
|
@ -416,15 +422,16 @@ class product_pricelist_item(osv.osv):
|
|||
"To have prices that end in 9.99, set rounding 10, surcharge -0.01" \
|
||||
),
|
||||
'price_min_margin': fields.float('Min. Price Margin',
|
||||
digits_compute= dp.get_precision('Product Price')),
|
||||
digits_compute= dp.get_precision('Product Price'), help='Specify the minimum amount of margin over the base price.'),
|
||||
'price_max_margin': fields.float('Max. Price Margin',
|
||||
digits_compute= dp.get_precision('Product Price')),
|
||||
digits_compute= dp.get_precision('Product Price'), help='Specify the maximum amount of margin over the base price.'),
|
||||
'company_id': fields.related('price_version_id','company_id',type='many2one',
|
||||
readonly=True, relation='res.company', string='Company', store=True)
|
||||
}
|
||||
|
||||
_constraints = [
|
||||
(_check_recursion, 'Error ! You cannot assign the Main Pricelist as Other Pricelist in PriceList Item!', ['base_pricelist_id'])
|
||||
(_check_recursion, 'Error! You cannot assign the Main Pricelist as Other Pricelist in PriceList Item!', ['base_pricelist_id']),
|
||||
(_check_margin, 'Error! The minimum margin should be lower than the maximum margin.', ['price_min_margin', 'price_max_margin'])
|
||||
]
|
||||
|
||||
def product_id_change(self, cr, uid, ids, product_id, context=None):
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
- name: 20% Discount given by my supplier
|
||||
sequence: 1
|
||||
price_min_margin: 2
|
||||
price_max_margin: -5
|
||||
price_max_margin: 5
|
||||
product_id: product_product_6
|
||||
base: -2
|
||||
-
|
||||
|
|
|
@ -49,14 +49,14 @@
|
|||
!python {model: product.product}: |
|
||||
context.update({'quantity':1, 'date': False, 'partner': ref('base.res_partner_4'), 'pricelist': ref("supplier_pricelist")})
|
||||
product = self.browse(cr, uid, ref("product_product_6"), context=context)
|
||||
assert product.price == 785, "cost price is not correspond."
|
||||
assert product.price == 792, "cost price is not correspond."
|
||||
-
|
||||
I check cost price of LCD Monitor if more than 3 Unit.
|
||||
-
|
||||
!python {model: product.product}: |
|
||||
context.update({'quantity':3})
|
||||
product = self.browse(cr, uid, ref("product_product_6"), context=context)
|
||||
assert product.price == 780, "cost price is not correspond."
|
||||
assert product.price == 787, "cost price is not correspond."
|
||||
|
||||
-
|
||||
I print the sale prices report.
|
||||
|
|
Loading…
Reference in New Issue