diff options
| author | qdp-odoo <qdp@odoo.com> | 2015-08-31 16:57:32 +0200 |
|---|---|---|
| committer | qdp-odoo <qdp@odoo.com> | 2015-08-31 16:57:32 +0200 |
| commit | e4dc50bf58d508d95b4ce9909af7e0ddfa2e46cf (patch) | |
| tree | 33fd37e1efec4643112b83a7c4b021746a21a598 /addons/product | |
| parent | ce3381aa633ab48723f896ebca5b25e4a51d6f97 (diff) | |
[IMP] pricelists improvements. Was PR #8228
Diffstat (limited to 'addons/product')
| -rw-r--r-- | addons/product/partner.py | 1 | ||||
| -rw-r--r-- | addons/product/partner_view.xml | 2 | ||||
| -rw-r--r-- | addons/product/pricelist.py | 367 | ||||
| -rw-r--r-- | addons/product/pricelist_view.xml | 249 | ||||
| -rw-r--r-- | addons/product/product.py | 91 | ||||
| -rw-r--r-- | addons/product/product_data.xml | 42 | ||||
| -rw-r--r-- | addons/product/product_demo.xml | 10 | ||||
| -rw-r--r-- | addons/product/product_pricelist_demo.yml | 86 | ||||
| -rw-r--r-- | addons/product/product_view.xml | 69 | ||||
| -rw-r--r-- | addons/product/security/ir.model.access.csv | 5 | ||||
| -rw-r--r-- | addons/product/security/product_security.xml | 16 | ||||
| -rw-r--r-- | addons/product/test/product_pricelist.yml | 6 | ||||
| -rw-r--r-- | addons/product/tests/test_pricelist.py | 42 |
13 files changed, 363 insertions, 623 deletions
diff --git a/addons/product/partner.py b/addons/product/partner.py index 08c5354afc3..35db117460c 100644 --- a/addons/product/partner.py +++ b/addons/product/partner.py @@ -11,7 +11,6 @@ class res_partner(osv.osv): 'property_product_pricelist': fields.property( type='many2one', relation='product.pricelist', - domain=[('type','=','sale')], string="Sale Pricelist", help="This pricelist will be used, instead of the default one, for sales to the current partner"), } diff --git a/addons/product/partner_view.xml b/addons/product/partner_view.xml index 813e8c9a59a..61a4d11186b 100644 --- a/addons/product/partner_view.xml +++ b/addons/product/partner_view.xml @@ -5,7 +5,7 @@ <field name="name">res.partner.product.property.form.inherit</field> <field name="model">res.partner</field> <field name="inherit_id" ref="base.view_partner_form"/> - <field name="groups_id" eval="[(4, ref('product.group_sale_pricelist')), (4, ref('product.group_purchase_pricelist'))]"/> + <field name="groups_id" eval="[(4, ref('product.group_sale_pricelist'))]"/> <field name="arch" type="xml"> <group name="sale"> <field name="property_product_pricelist" groups="product.group_sale_pricelist" attrs="{'invisible': [('is_company','=',False),('parent_id','!=',False)]}"/> diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index 3f11cde9948..a70d8bc7ea3 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -5,79 +5,18 @@ from itertools import chain import time from openerp import tools +from openerp.tools import DEFAULT_SERVER_DATE_FORMAT from openerp.osv import fields, osv from openerp.tools.translate import _ import openerp.addons.decimal_precision as dp from openerp.exceptions import UserError - -class price_type(osv.osv): - """ - The price type is used to points which field in the product form - is a price and in which currency is this price expressed. - When a field is a price, you can use it in pricelists to base - sale and purchase prices based on some fields of the product. - """ - def _price_field_get(self, cr, uid, context=None): - mf = self.pool.get('ir.model.fields') - ids = mf.search(cr, uid, [('model','in', (('product.product'),('product.template'))), ('ttype','=','float')], context=context) - res = [] - for field in mf.browse(cr, uid, ids, context=context): - if not (field.name, field.field_description) in res: - res.append((field.name, field.field_description)) - return res - - def _get_field_currency(self, cr, uid, fname, ctx): - ids = self.search(cr, uid, [('field','=',fname)], context=ctx) - return self.browse(cr, uid, ids, context=ctx)[0].currency_id - - def _get_currency(self, cr, uid, ctx): - comp = self.pool.get('res.users').browse(cr,uid,uid).company_id - if not comp: - comp_id = self.pool.get('res.company').search(cr, uid, [])[0] - comp = self.pool.get('res.company').browse(cr, uid, comp_id) - return comp.currency_id.id - - _name = "product.price.type" - _description = "Price Type" - _columns = { - "name" : fields.char("Price Name", required=True, translate=True, help="Name of this kind of price."), - "active" : fields.boolean("Active"), - "field" : fields.selection(_price_field_get, "Product Field", size=32, required=True, help="Associated field in the product form."), - "currency_id" : fields.many2one('res.currency', "Currency", required=True, help="The currency the field is expressed in."), - } - _defaults = { - "active": lambda *args: True, - "currency_id": _get_currency - } - - #---------------------------------------------------------- # Price lists #---------------------------------------------------------- -class product_pricelist_type(osv.osv): - _name = "product.pricelist.type" - _description = "Pricelist Type" - _columns = { - 'name': fields.char('Name', required=True, translate=True), - 'key': fields.char('Key', required=True, help="Used in the code to select specific prices based on the context. Keep unchanged."), - } - - class product_pricelist(osv.osv): - def _pricelist_type_get(self, cr, uid, context=None): - pricelist_type_obj = self.pool.get('product.pricelist.type') - pricelist_type_ids = pricelist_type_obj.search(cr, uid, [], order='name') - pricelist_types = pricelist_type_obj.read(cr, uid, pricelist_type_ids, ['key','name'], context=context) - - res = [] - - for type in pricelist_types: - res.append((type['key'],type['name'])) - - return res _name = "product.pricelist" _description = "Pricelist" @@ -85,8 +24,7 @@ class product_pricelist(osv.osv): _columns = { 'name': fields.char('Pricelist Name', required=True, translate=True), 'active': fields.boolean('Active', help="If unchecked, it will allow you to hide the pricelist without removing it."), - 'type': fields.selection(_pricelist_type_get, 'Pricelist Type', required=True), - 'version_id': fields.one2many('product.pricelist.version', 'pricelist_id', 'Pricelist Versions', copy=True), + 'item_ids': fields.one2many('product.pricelist.item', 'pricelist_id', 'Pricelist Items', copy=True), 'currency_id': fields.many2one('res.currency', 'Currency', required=True), 'company_id': fields.many2one('res.company', 'Company'), } @@ -139,7 +77,6 @@ class product_pricelist(osv.osv): return super(product_pricelist, self).name_search( cr, uid, name, args, operator=operator, context=context, limit=limit) - def _get_currency(self, cr, uid, ctx): comp = self.pool.get('res.users').browse(cr, uid, uid).company_id if not comp: @@ -152,9 +89,6 @@ class product_pricelist(osv.osv): "currency_id": _get_currency } - def price_get_multi(self, cr, uid, ids, products_by_qty_by_partner, context=None): - return dict((key, dict((key, price[0]) for key, price in value.items())) for key, value in self.price_rule_get_multi(cr, uid, ids, products_by_qty_by_partner, context=context).items()) - def price_rule_get_multi(self, cr, uid, ids, products_by_qty_by_partner, context=None): """multi products 'price_get'. @param ids: @@ -169,7 +103,7 @@ class product_pricelist(osv.osv): results = {} for pricelist in self.browse(cr, uid, ids, context=context): subres = self._price_rule_get_multi(cr, uid, pricelist, products_by_qty_by_partner, context=context) - for product_id,price in subres.items(): + for product_id, price in subres.items(): results.setdefault(product_id, {}) results[product_id][pricelist.id] = price return results @@ -179,25 +113,13 @@ class product_pricelist(osv.osv): def _price_rule_get_multi(self, cr, uid, pricelist, products_by_qty_by_partner, context=None): context = context or {} - date = context.get('date') or time.strftime('%Y-%m-%d') - date = date[0:10] - + date = context.get('date') and context['date'][0:10] or time.strftime(DEFAULT_SERVER_DATE_FORMAT) products = map(lambda x: x[0], products_by_qty_by_partner) - currency_obj = self.pool.get('res.currency') - product_obj = self.pool.get('product.template') product_uom_obj = self.pool.get('product.uom') - price_type_obj = self.pool.get('product.price.type') if not products: return {} - version = False - for v in pricelist.version_id: - if ((v.date_start is False) or (v.date_start <= date)) and ((v.date_end is False) or (v.date_end >= date)): - version = v - break - if not version: - raise UserError(_("At least one pricelist has no active version !\nPlease create or activate one.")) categ_ids = {} for p in products: categ = p.categ_id @@ -220,22 +142,20 @@ class product_pricelist(osv.osv): cr.execute( 'SELECT i.id ' 'FROM product_pricelist_item AS i ' - 'WHERE (product_tmpl_id IS NULL OR product_tmpl_id = any(%s)) ' - 'AND (product_id IS NULL OR (product_id = any(%s))) ' - 'AND ((categ_id IS NULL) OR (categ_id = any(%s))) ' - 'AND (price_version_id = %s) ' - 'ORDER BY sequence, min_quantity desc', - (prod_tmpl_ids, prod_ids, categ_ids, version.id)) - + 'WHERE (product_tmpl_id IS NULL OR product_tmpl_id = any(%s))' + 'AND (product_id IS NULL OR product_id = any(%s))' + 'AND (categ_id IS NULL OR categ_id = any(%s)) ' + 'AND (pricelist_id = %s) ' + 'AND ((i.date_start IS NULL OR i.date_start<=%s) AND (i.date_end IS NULL OR i.date_end>=%s))' + 'ORDER BY applied_on, min_quantity desc', + (prod_tmpl_ids, prod_ids, categ_ids, pricelist.id, date, date)) + item_ids = [x[0] for x in cr.fetchall()] items = self.pool.get('product.pricelist.item').browse(cr, uid, item_ids, context=context) - - price_types = {} - results = {} for product, qty, partner in products_by_qty_by_partner: results[product.id] = 0.0 - rule_id = False + suitable_rule = False # Final unit price is computed according to `qty` in the `qty_uom_id` UoM. # An intermediary unit price may be computed according to a different UoM, in @@ -252,9 +172,10 @@ class product_pricelist(osv.osv): # Ignored - incompatible UoM in context, use default product UoM pass - price_type = 'standard_price' if pricelist.type == 'purchase' else 'list_price' # if Public user try to access standard price from website sale, need to call _price_get. - price = product_obj._price_get(cr, uid, [product], price_type, context=context)[product.id] or False + price = self.pool['product.template']._price_get(cr, uid, [product], 'list_price', context=context)[product.id] + + price_uom_id = qty_uom_id for rule in items: if rule.min_quantity and qty_in_product_uom < rule.min_quantity: continue @@ -271,68 +192,50 @@ class product_pricelist(osv.osv): if rule.product_id and product.id != rule.product_id.id: continue - if rule.base == -1: - if rule.base_pricelist_id: - price_tmp = self._price_get_multi(cr, uid, - rule.base_pricelist_id, [(product, - qty, partner)], context=context)[product.id] - ptype_src = rule.base_pricelist_id.currency_id.id - price_uom_id = qty_uom_id - price = currency_obj.compute(cr, uid, - ptype_src, pricelist.currency_id.id, - price_tmp, round=False, - context=context) + if rule.base == 'pricelist' and rule.base_pricelist_id: + price_tmp = self._price_get_multi(cr, uid, rule.base_pricelist_id, [(product, qty, partner)], context=context)[product.id] + ptype_src = rule.base_pricelist_id.currency_id.id + price = self.pool['res.currency'].compute(cr, uid, ptype_src, pricelist.currency_id.id, price_tmp, round=False, context=context) else: - if rule.base not in price_types: - price_types[rule.base] = price_type_obj.browse(cr, uid, int(rule.base)) - price_type = price_types[rule.base] - + # if base option is public price take sale price else cost price of product # price_get returns the price in the context UoM, i.e. qty_uom_id - price_uom_id = qty_uom_id - price = currency_obj.compute( - cr, uid, - price_type.currency_id.id, pricelist.currency_id.id, - product_obj._price_get(cr, uid, [product], price_type.field, context=context)[product.id], - round=False, context=context) - for seller in product.seller_ids: - partner = partner.id if partner and not isinstance(partner, int) else partner - if seller.name.id == partner: - qty_in_seller = qty - seller_uom = seller.product_uom and seller.product_uom.id or False - if qty_uom_id != seller_uom: - qty_in_seller = product_uom_obj._compute_qty(cr, uid, qty_uom_id, qty, to_uom_id=seller_uom) - for line in seller.pricelist_ids: - if line.min_quantity <= qty_in_seller: - price = line.price + price = self.pool['product.template']._price_get(cr, uid, [product], rule.base, context=context)[product.id] + + convert_to_price_uom = (lambda price: product_uom_obj._compute_price( + cr, uid, product.uom_id.id, + price, price_uom_id)) if price is not False: - price_limit = price - price = price * (1.0+(rule.price_discount or 0.0)) - if rule.price_round: - price = tools.float_round(price, precision_rounding=rule.price_round) - - convert_to_price_uom = (lambda price: product_uom_obj._compute_price( - cr, uid, product.uom_id.id, - price, price_uom_id)) - if rule.price_surcharge: - price_surcharge = convert_to_price_uom(rule.price_surcharge) - price += price_surcharge - - if rule.price_min_margin: - price_min_margin = convert_to_price_uom(rule.price_min_margin) - price = max(price, price_limit + price_min_margin) - - if rule.price_max_margin: - price_max_margin = convert_to_price_uom(rule.price_max_margin) - price = min(price, price_limit + price_max_margin) - - rule_id = rule.id + if rule.compute_price == 'fixed': + price = convert_to_price_uom(rule.fixed_price) + elif rule.compute_price == 'percentage': + price = (price - (price * (rule.percent_price / 100))) or 0.0 + else: + #complete formula + price_limit = price + price = (price - (price * (rule.price_discount / 100))) or 0.0 + if rule.price_round: + price = tools.float_round(price, precision_rounding=rule.price_round) + + if rule.price_surcharge: + price_surcharge = convert_to_price_uom(rule.price_surcharge) + price += price_surcharge + + if rule.price_min_margin: + price_min_margin = convert_to_price_uom(rule.price_min_margin) + price = max(price, price_limit + price_min_margin) + + if rule.price_max_margin: + price_max_margin = convert_to_price_uom(rule.price_max_margin) + price = min(price, price_limit + price_max_margin) + suitable_rule = rule break + # Final price conversion into pricelist currency + if suitable_rule and suitable_rule.compute_price != 'fixed' and suitable_rule.base != 'pricelist': + user_company = self.pool['res.users'].browse(cr, uid, uid, context=context).company_id + price = self.pool['res.currency'].compute(cr, uid, user_company.currency_id.id, pricelist.currency_id.id, price, context=context) - # Final price conversion to target UoM - price = product_uom_obj._compute_price(cr, uid, price_uom_id, price, qty_uom_id) - - results[product.id] = (price, rule_id) + results[product.id] = (price, suitable_rule and suitable_rule.id or False) return results def price_get(self, cr, uid, ids, prod_id, qty, partner=None, context=None): @@ -344,104 +247,15 @@ class product_pricelist(osv.osv): res = res_multi[prod_id] return res - -class product_pricelist_version(osv.osv): - _name = "product.pricelist.version" - _description = "Pricelist Version" - _columns = { - 'pricelist_id': fields.many2one('product.pricelist', 'Price List', - required=True, select=True, ondelete='cascade'), - 'name': fields.char('Name', required=True, translate=True), - 'active': fields.boolean('Active', - help="When a version is duplicated it is set to non active, so that the " \ - "dates do not overlaps with original version. You should change the dates " \ - "and reactivate the pricelist"), - 'items_id': fields.one2many('product.pricelist.item', - 'price_version_id', 'Price List Items', required=True, copy=True), - 'date_start': fields.date('Start Date', help="First valid date for the version."), - 'date_end': fields.date('End Date', help="Last valid date for the version."), - 'company_id': fields.related('pricelist_id','company_id',type='many2one', - readonly=True, relation='res.company', string='Company', store=True) - } - _defaults = { - 'active': lambda *a: 1, - } - - def _check_date(self, cursor, user, ids, context=None): - for pricelist_version in self.browse(cursor, user, ids, context=context): - if not pricelist_version.active: - continue - where = [] - if pricelist_version.date_start: - where.append("((date_end>='%s') or (date_end is null))" % (pricelist_version.date_start,)) - if pricelist_version.date_end: - where.append("((date_start<='%s') or (date_start is null))" % (pricelist_version.date_end,)) - - cursor.execute('SELECT id ' \ - 'FROM product_pricelist_version ' \ - 'WHERE '+' and '.join(where) + (where and ' and ' or '')+ - 'pricelist_id = %s ' \ - 'AND active ' \ - 'AND id <> %s', ( - pricelist_version.pricelist_id.id, - pricelist_version.id)) - if cursor.fetchall(): - return False - return True - - _constraints = [ - (_check_date, 'You cannot have 2 pricelist versions that overlap!', - ['date_start', 'date_end']) - ] - - def copy(self, cr, uid, id, default=None, context=None): - # set active False to prevent overlapping active pricelist - # versions - if not default: - default = {} - default['active'] = False - return super(product_pricelist_version, self).copy(cr, uid, id, default, context=context) - class product_pricelist_item(osv.osv): - def _price_field_get(self, cr, uid, context=None): - pt = self.pool.get('product.price.type') - ids = pt.search(cr, uid, [], context=context) - result = [] - for line in pt.browse(cr, uid, ids, context=context): - result.append((line.id, line.name)) - - result.append((-1, _('Other Pricelist'))) - return result - -# Added default function to fetch the Price type Based on Pricelist type. - def _get_default_base(self, cr, uid, fields, context=None): - product_price_type_obj = self.pool.get('product.price.type') - if fields.get('type') == 'purchase': - product_price_type_ids = product_price_type_obj.search(cr, uid, [('field', '=', 'standard_price')], context=context) - elif fields.get('type') == 'sale': - product_price_type_ids = product_price_type_obj.search(cr, uid, [('field','=','list_price')], context=context) - else: - return -1 - if not product_price_type_ids: - return False - else: - pricetype = product_price_type_obj.browse(cr, uid, product_price_type_ids, context=context)[0] - return pricetype.id - _name = "product.pricelist.item" _description = "Pricelist item" - _order = "sequence, min_quantity desc" - _defaults = { - 'base': _get_default_base, - 'min_quantity': lambda *a: 0, - 'sequence': lambda *a: 5, - 'price_discount': lambda *a: 0, - } + _order = "applied_on, min_quantity desc" def _check_recursion(self, cr, uid, ids, context=None): for obj_list in self.browse(cr, uid, ids, context=context): - if obj_list.base == -1: - main_pricelist = obj_list.price_version_id.pricelist_id.id + if obj_list.base == 'pricelist': + main_pricelist = obj_list.pricelist_id.id other_pricelist = obj_list.base_pricelist_id.id if main_pricelist == other_pricelist: return False @@ -453,26 +267,48 @@ class product_pricelist_item(osv.osv): return False return True + def _get_pricelist_item_name_price(self, cr, uid, ids, fields, args, context=None): + """This function is used to set some fields used for usability purposes only (state explicitly what a rule does) + """ + res = {} + for item in self.browse(cr, uid, ids, context=context): + res[item.id] = {'name': '', 'price': ''} + if item.categ_id: + res[item.id]['name'] = _("Category: %s") % (item.categ_id.name) + elif item.product_tmpl_id: + res[item.id]['name'] = item.product_tmpl_id.name + elif item.product_id: + res[item.id]['name'] = item.product_id.display_name.replace('[%s]' % item.product_id.code, '') + else: + res[item.id]['name'] = _("All Products") + + if item.compute_price == 'fixed': + res[item.id]['price'] = ("%s %s") % (item.fixed_price, item.pricelist_id.currency_id.name) + elif item.compute_price == 'percentage': + res[item.id]['price'] = _("%s %% discount") % (item.percent_price) + else: + res[item.id]['price'] = _("%s %% discount and %s surcharge") % (abs(item.price_discount), item.price_surcharge) + return res + _columns = { - 'name': fields.char('Rule Name', 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'), 'product_tmpl_id': fields.many2one('product.template', 'Product Template', ondelete='cascade', help="Specify a template if this rule only applies to one product template. Keep empty otherwise."), 'product_id': fields.many2one('product.product', 'Product', ondelete='cascade', help="Specify a product if this rule only applies to one product. Keep empty otherwise."), 'categ_id': fields.many2one('product.category', 'Product Category', ondelete='cascade', help="Specify a product category if this rule only applies to products belonging to this category or its children categories. Keep empty otherwise."), - 'min_quantity': fields.integer('Min. Quantity', required=True, + 'min_quantity': fields.integer('Min. Quantity', help="For the rule to apply, bought/sold quantity must be greater " "than or equal to the minimum quantity specified in this field.\n" "Expressed in the default unit of measure of the product." ), + 'applied_on': fields.selection([('3_global', 'Global'),('2_product_category', ' Product Category'), ('1_product', 'Product'), ('0_product_variant', 'Product Variant')], string="Apply On", required=True, + help='Pricelist Item applicable on selected option'), '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, # here use size=-1 to store the values as integers - help='Base price for computation. \n Public Price: The base price will be the Sale/public Price. \n Vendor Section on Product or Cost Price : The base price will be the vendor price if it is set, otherwise it will be the cost price. \n Other Pricelist : Computation of the base price based on another Pricelist.'), + 'base': fields.selection([('list_price', 'Public Price'), ('standard_price', 'Cost'), ('pricelist', 'Other Pricelist')], string="Based on", required=True, + help='Base price for computation. \n Public Price: The base price will be the Sale/public Price. \n Cost Price : The base price will be the cost price. \n Other Pricelist : Computation of the base price based on another Pricelist.'), 'base_pricelist_id': fields.many2one('product.pricelist', 'Other Pricelist'), - + 'pricelist_id': fields.many2one('product.pricelist', 'Pricelist'), 'price_surcharge': fields.float('Price Surcharge', 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_discount': fields.float('Price Discount', digits=(16,2)), 'price_round': fields.float('Price Rounding', digits_compute= dp.get_precision('Product Price'), help="Sets the price so that it is a multiple of this value.\n" \ @@ -483,19 +319,28 @@ class product_pricelist_item(osv.osv): 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'), 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) + 'company_id': fields.related('pricelist_id','company_id',type='many2one', + readonly=True, relation='res.company', string='Company', store=True), + 'currency_id': fields.related('pricelist_id', 'currency_id', type='many2one', + readonly=True, relation='res.currency', string='Currency', store=True), + 'date_start': fields.date('Start Date', help="Starting date for the pricelist item validation"), + 'date_end': fields.date('End Date', help="Ending valid for the pricelist item validation"), + 'compute_price': fields.selection([('fixed', 'Fix Price'), ('percentage', 'Percentage (discount)'), ('formula', 'Formula')], select=True, default='fixed'), + 'fixed_price': fields.float('Fixed Price'), + 'percent_price': fields.float('Percentage Price'), + #functional fields used for usability purposes + 'name': fields.function(_get_pricelist_item_name_price, type="char", string='Name', multi='item_name_price', help="Explicit rule name for this pricelist line."), + 'price': fields.function(_get_pricelist_item_name_price, type="char", string='Price', multi='item_name_price', help="Explicit rule name for this pricelist line."), } + _defaults = { + 'base': 'list_price', + 'min_quantity': 1, + 'sequence': 5, + 'price_discount': 0, + 'applied_on': '3_global', + } _constraints = [ (_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): - if not product_id: - return {} - prod = self.pool.get('product.product').read(cr, uid, [product_id], ['code','name']) - if prod[0]['code']: - return {'value': {'name': prod[0]['code']}} - return {} diff --git a/addons/product/pricelist_view.xml b/addons/product/pricelist_view.xml index 9608b10c45f..7fd93edce64 100644 --- a/addons/product/pricelist_view.xml +++ b/addons/product/pricelist_view.xml @@ -7,77 +7,19 @@ <menuitem id="menu_product_pricelist_main" name="Pricelists" parent="base.menu_sale_config" groups="product.group_sale_pricelist" sequence="3"/> - <record id="product_pricelist_version_form_view" model="ir.ui.view"> - <field name="name">product.pricelist.version.form</field> - <field name="model">product.pricelist.version</field> - <field name="arch" type="xml"> - <form string="Pricelist Version"> - <group> - <group> - <field name="name"/> - <field name="pricelist_id"/> - <field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/> - </group> - <group> - <field name="date_start"/> - <field name="date_end"/> - <field name="active"/> - </group> - </group> - <notebook> - <page string="Item List"> - <field name="items_id"/> - </page> - </notebook> - </form> - </field> - </record> - <record id="product_pricelist_version_tree_view" model="ir.ui.view"> - <field name="name">product.pricelist.version.tree</field> - <field name="model">product.pricelist.version</field> - <field name="arch" type="xml"> - <tree string="Pricelist Version"> - <field name="name"/> - <field name="pricelist_id"/> - <field name="date_start"/> - <field name="date_end"/> - </tree> - </field> - </record> - - <record id="product_pricelist_action" model="ir.actions.act_window"> - <field name="name">Pricelist Versions</field> - <field name="type">ir.actions.act_window</field> - <field name="res_model">product.pricelist.version</field> - <field name="view_type">form</field> - <field name="view_id" ref="product_pricelist_version_tree_view"/> - <field name="help" type="html"> - <p class="oe_view_nocontent_create"> - Click to add a pricelist version. - </p><p> - There can be more than one version of a pricelist, each of - these must be valid during a certain period of time. Some - examples of versions: Main Prices, 2010, 2011, Summer Sales, - etc. - </p> - </field> - </record> - <menuitem - action="product_pricelist_action" id="menu_product_pricelist_action" - parent="product.menu_product_pricelist_main" sequence="2"/> - <record id="product_pricelist_item_tree_view" model="ir.ui.view"> <field name="name">product.pricelist.item.tree</field> <field name="model">product.pricelist.item</field> <field name="arch" type="xml"> - <tree string="Products Listprices Items"> - <field name="sequence"/> + <tree string="Pricelist Items"> + <field name="sequence" widget="handle"/> <field colspan="4" name="name"/> <field name="product_id" groups="product.group_product_variant"/> <field name="product_tmpl_id"/> <field name="categ_id"/> <field name="min_quantity"/> - <field name="base"/> + <field name="date_start"/> + <field name="date_end"/> </tree> </field> </record> @@ -86,39 +28,55 @@ <field name="name">product.pricelist.item.form</field> <field name="model">product.pricelist.item</field> <field name="arch" type="xml"> - <form string="Products Listprices Items"> - <label for="name" class="oe_edit_only"/> + <form string="Pricelist Items"> <h1><field name="name"/></h1> - - <group col="4"> - <field name="product_id" on_change="product_id_change(product_id)" groups="product.group_product_variant"/> - <field name="product_tmpl_id"/> - <field name="categ_id"/> - <field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/> - <field name="min_quantity"/> - <field name="sequence"/> + <group> + <group> + <field name="applied_on" widget="radio"/> + <field name="categ_id" attrs="{'invisible':[('applied_on', '!=', '2_product_category')], 'required':[('applied_on', '=', '2_product_category')]}"/> + <field name="product_tmpl_id" attrs="{'invisible':[('applied_on', '!=', '1_product')],'required':[('applied_on', '=', '1_product')]}" string="Product"/> + <field name="product_id" attrs="{'invisible':[('applied_on', '!=', '0_product_variant')],'required':[('applied_on', '=', '0_product_variant')]}" string="Product Variant"/> + </group> + <group> + <field name="min_quantity"/> + <field name="date_start"/> + <field name="date_end"/> + </group> </group> <separator string="Price Computation"/> + <group> + <group> + <label for="compute_price" string="Compute Price"/> + <div> + <field name="compute_price" widget="radio"/> + <field name="currency_id" invisible="1"/> + <div attrs="{'invisible':[('compute_price', '!=', 'fixed')]}"> + <field name="fixed_price" nolabel= "1" widget='monetary' options="{'currency_field': 'currency_id'}"/></div> + <div attrs="{'invisible':[('compute_price', '!=', 'percentage')]}"> + <field name="percent_price" nolabel="1" class="oe_inline"/>%% + </div> + </div> + </group> + </group> <div class="oe_grey" groups="product.group_uom"> <p>The computed price is expressed in the default Unit of Measure of the product.</p> </div> - <group col="4"> - <field name="base"/> - <field name="base_pricelist_id" attrs="{'invisible':[('base', '!=', -1)],'required': [('base','=', -1)], 'readonly': [('base','!=', -1)]}"/> - </group> - <group col="6" colspan="5"> - <label string="New Price ="/> - <label string="Base Price"/> - <label string="* ( 1 + "/> - <field name="price_discount" nolabel="1"/> - <label string=" ) + "/> - <field name="price_surcharge" nolabel="1"/> - <newline/> - <field name="price_round" string="Rounding Method"/> - <field name="price_min_margin" string="Min. Margin"/> - <field name="price_max_margin" string="Max. Margin"/> + <group attrs="{'invisible':[('compute_price', '!=', 'formula')]}"> + <group col="6" colspan="6"> + <field name="base" colspan="6"/> + <label string="New Price ="/> + <label string="Public Price - " attrs="{'invisible':[('base', 'not in', ('list_price','standard_price'))]}"/> + <label string="Other Pricelist - " attrs="{'invisible':[('base', '!=', 'pricelist')]}"/> + <div><field name="price_discount" nolabel="1" class="oe_inline"/>%%</div> + <label string=" + "/> + <field name="price_surcharge" nolabel="1"/> + <newline/> + <field name="price_round" string="Rounding Method"/> + <field name="price_min_margin" string="Min. Margin"/> + <field name="price_max_margin" string="Max. Margin"/> + <field name="base_pricelist_id" attrs="{'invisible':[('base', '!=', 'pricelist')],'required': [('base','=', 'pricelist')], 'readonly': [('base','!=', 'pricelist')]}"/> + </group> </group> - </form> </field> </record> @@ -129,8 +87,7 @@ <field name="arch" type="xml"> <search string="Products Price Search"> <field name="name" string="Products Price"/> - <field name="type"/> - <field name="active" /> + <field name="active"/> <field name="currency_id" groups="base.group_multi_currency"/> </search> </field> @@ -143,9 +100,7 @@ <field name="arch" type="xml"> <tree string="Products Price List"> <field name="name"/> - <field name="type"/> <field name="currency_id" groups="base.group_multi_currency"/> - <field name="active" /> </tree> </field> </record> @@ -154,33 +109,34 @@ <field name="model">product.pricelist</field> <field name="arch" type="xml"> <form string="Products Price List"> - <label for="name" class="oe_edit_only"/> - <h1> - <field name="name"/> - </h1> - <group col="4"> - <field name="active"/> - <field name="type"/> - <field name="currency_id" groups="base.group_multi_currency"/> - <field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/> - </group> - <field name="version_id" context="{'type':type}"> - <form string="Pricelist Version"> - <group col="4"> + <sheet> + <div class="oe_title"> + <h1> <field name="name"/> + </h1> + </div> + <group col="4"> + <group> <field name="active"/> - <field name="date_start"/> - <field name="date_end"/> </group> - <field name="items_id" context="{'type':parent.type}"/> - </form> - <tree string="Pricelist Version"> - <field name="name"/> - <field name="active"/> - <field name="date_start"/> - <field name="date_end"/> - </tree> - </field> + <group> + <field name="currency_id" groups="base.group_multi_currency"/> + <field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/> + </group> + </group> + <div groups="product.group_pricelist_item"> + <separator string="Pricelist Items"/> + <field name="item_ids" nolabel="1" context="{'default_base':'list_price'}"> + <tree string="Pricelist Items"> + <field name="name" string="Applicable On"/> + <field name="min_quantity"/> + <field name="date_start"/> + <field name="date_end"/> + <field name="price" string="Price"/> + </tree> + </field> + </div> + </sheet> </form> </field> </record> @@ -191,7 +147,7 @@ <field name="view_type">form</field> <field name="view_mode">tree,form</field> <field name="search_view_id" ref="product_pricelist_view_search" /> - <field name="context">{"default_type":"sale", "search_default_type":"sale"}</field> + <field name="context">{"default_base":'list_price'}</field> <field name="help" type="html"> <p class="oe_view_nocontent_create"> Click to create a pricelist. @@ -199,66 +155,15 @@ A price list contains rules to be evaluated in order to compute the sales price of the products. </p><p> - Price lists may have several versions (2010, 2011, Promotion of - February 2010, etc.) and each version may have several rules. - (e.g. the customer price of a product category will be based on - the supplier price multiplied by 1.80). - </p> - </field> - </record> - <record id="product_pricelist_action_for_purchase" model="ir.actions.act_window"> - <field name="name">Pricelists</field> - <field name="type">ir.actions.act_window</field> - <field name="res_model">product.pricelist</field> - <field name="view_type">form</field> - <field name="view_mode">tree,form</field> - <field name="search_view_id" ref="product_pricelist_view_search" /> - <field name="context">{"default_type":"purchase", "search_default_type":"purchase"}</field> - <field name="help" type="html"> - <p class="oe_view_nocontent_create"> - Click to create a pricelist. - </p><p> - A price list contains rules to be evaluated in order to compute - the purchase price. The default price list has only one rule; use - the cost price defined on the product form, so that you do not have to - worry about supplier pricelists if you have very simple needs. - </p><p> - But you can also import complex price lists form your supplier - that may depends on the quantities ordered or the current - promotions. + Each rule include a set of applicability criteria (date range, + product category...) and a computation that easily helps to achieve + any kind of pricing. </p> </field> </record> + <menuitem action="product_pricelist_action2" id="menu_product_pricelist_action2" parent="product.menu_product_pricelist_main" sequence="1" groups="product.group_sale_pricelist"/> - - <record id="product_price_type_view" model="ir.ui.view"> - <field name="name">product.price.type.form</field> - <field name="model">product.price.type</field> - <field name="arch" type="xml"> - <form string="Products Price Type"> - <group col="4"> - <field name="name"/> - <field name="active"/> - <field name="field"/> - <field name="currency_id" groups="base.group_multi_currency"/> - </group> - </form> - </field> - </record> - - <record id="product_price_type_action" model="ir.actions.act_window"> - <field name="name">Price Types</field> - <field name="type">ir.actions.act_window</field> - <field name="res_model">product.price.type</field> - <field name="view_type">form</field> - <field name="view_mode">tree,form</field> - </record> - - <menuitem - action="product_price_type_action" id="menu_product_price_type" - parent="product.menu_product_pricelist_main" sequence="4" groups="base.group_no_one"/> - </data> </openerp> diff --git a/addons/product/product.py b/addons/product/product.py index a03a80b6772..649c69f9eef 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -7,7 +7,7 @@ import time from openerp import api, tools, SUPERUSER_ID from openerp.osv import osv, fields, expression from openerp.tools.translate import _ -from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT +from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT, DEFAULT_SERVER_DATE_FORMAT import psycopg2 import openerp.addons.decimal_precision as dp @@ -400,7 +400,7 @@ class product_template(osv.osv): products = self.browse(cr, uid, ids, context=context) qtys = map(lambda x: (x, quantity, partner), products) pl = plobj.browse(cr, uid, pricelist, context=context) - price = plobj._price_get_multi(cr,uid, pl, qtys, context=context) + price = plobj._price_get_multi(cr, uid, pl, qtys, context=context) for id in ids: res[id] = price.get(id, 0.0) for id in ids: @@ -466,6 +466,28 @@ class product_template(osv.osv): return variant.write({name: value}) return {} + def _select_seller(self, cr, uid, ids, name, arg, context=None): + if context is None: + context = {} + res = {} + partner = context.get('partner') + minimal_quantity = context.get('quantity', 0.0) + date = context.get('date', time.strftime(DEFAULT_SERVER_DATE_FORMAT)) + for product in self.browse(cr, uid, ids, context=context): + res[product.id] = False + for seller in product.seller_ids: + if seller.date_start and seller.date_start > date: + continue + if seller.date_end and seller.date_end < date: + continue + if partner and seller.name.id != partner: + continue + if minimal_quantity and minimal_quantity < seller.qty: + continue + res[product.id] = seller + break + return res + def _get_product_template_type(self, cr, uid, context=None): return [('consu', 'Consumable'), ('service', 'Service')] _get_product_template_type_wrapper = lambda self, *args, **kwargs: self._get_product_template_type(*args, **kwargs) @@ -531,38 +553,35 @@ class product_template(osv.osv): help="Gives the different ways to package the same product. This has no impact on " "the picking order and is mainly used if you use the EDI module."), 'seller_ids': fields.one2many('product.supplierinfo', 'product_tmpl_id', 'Vendor'), - 'seller_delay': fields.related('seller_ids','delay', type='integer', string='Vendor Lead Time', + 'selected_seller_id': fields.function(_select_seller, type='many2one', relation='product.supplierinfo', string='Selected Seller', help='Technical field that selects a seller based on priority (sequence) and an optional partner and/or a minimal quantity in the context'), + 'seller_delay': fields.related('selected_seller_id','delay', type='integer', string='Vendor Lead Time', help="This is the average delay in days between the purchase order confirmation and the receipts for this product and for the default vendor. It is used by the scheduler to order requests based on reordering delays."), - 'seller_qty': fields.related('seller_ids','qty', type='float', string='Vendor Quantity', + 'seller_qty': fields.related('selected_seller_id','qty', type='float', string='Vendor Quantity', help="This is minimum quantity to purchase from Main Vendor."), - 'seller_id': fields.related('seller_ids','name', type='many2one', relation='res.partner', string='Main Vendor', + 'seller_id': fields.related('selected_seller_id','name', type='many2one', relation='res.partner', string='Main Vendor', help="Main vendor who has highest priority in vendor list."), + 'seller_price': fields.related('selected_seller_id','price', type='float', string='Vendor Price', help="Purchase price from from Main Vendor."), 'active': fields.boolean('Active', help="If unchecked, it will allow you to hide the product without removing it."), 'color': fields.integer('Color Index'), - 'is_product_variant': fields.function( _is_product_variant, type='boolean', string='Is a product variant'), + 'is_product_variant': fields.function(_is_product_variant, type='boolean', string='Is a product variant'), 'attribute_line_ids': fields.one2many('product.attribute.line', 'product_tmpl_id', 'Product Attributes'), 'product_variant_ids': fields.one2many('product.product', 'product_tmpl_id', 'Products', required=True), - 'product_variant_count': fields.function( _get_product_variant_count, type='integer', string='# of Product Variants'), + 'product_variant_count': fields.function(_get_product_variant_count, type='integer', string='# of Product Variants'), # related to display product product information if is_product_variant 'barcode': fields.related('product_variant_ids', 'barcode', type='char', string='Barcode', oldname='ean13'), 'default_code': fields.related('product_variant_ids', 'default_code', type='char', string='Internal Reference'), + 'item_ids': fields.one2many('product.pricelist.item', 'product_tmpl_id', 'Pricelist Items'), } - def _price_get_list_price(self, product): - return 0.0 - def _price_get(self, cr, uid, products, ptype='list_price', context=None): if context is None: context = {} if 'currency_id' in context: - pricetype_obj = self.pool.get('product.price.type') - price_type_id = pricetype_obj.search(cr, uid, [('field','=',ptype)])[0] - price_type_currency_id = pricetype_obj.browse(cr,uid,price_type_id).currency_id.id - + currency_id = self.pool['res.users'].browse(cr, uid, uid, context=context).company_id.currency_id.id res = {} product_uom_obj = self.pool.get('product.uom') for product in products: @@ -581,13 +600,12 @@ class product_template(osv.osv): uom = product.uom_id res[product.id] = product_uom_obj._compute_price(cr, uid, uom.id, res[product.id], context['uom']) - # Convert from price_type currency to asked one + # Convert from current user company currency to asked one if 'currency_id' in context: - # Take the price_type currency from the product field + # Take current user company currency. # This is right cause a field cannot be in more than one currency - res[product.id] = self.pool.get('res.currency').compute(cr, uid, price_type_currency_id, - context['currency_id'], res[product.id],context=context) - + res[product.id] = self.pool.get('res.currency').compute(cr, uid, currency_id, + context['currency_id'], res[product.id], context=context) return res def _get_uom_id(self, cr, uid, *args): @@ -1173,6 +1191,8 @@ class product_packaging(osv.osv): class product_supplierinfo(osv.osv): _name = "product.supplierinfo" _description = "Information about a product vendor" + _order = 'sequence, min_qty desc, price' + def _calc_qty(self, cr, uid, ids, fields, arg, context=None): result = {} for supplier_info in self.browse(cr, uid, ids, context=context): @@ -1183,37 +1203,30 @@ class product_supplierinfo(osv.osv): return result _columns = { - 'name' : fields.many2one('res.partner', 'Vendor', required=True,domain = [('supplier','=',True)], ondelete='cascade', help="Vendor of this product"), + 'name': fields.many2one('res.partner', 'Vendor', required=True, domain=[('supplier', '=', True)], ondelete='cascade', help="Vendor of this product"), 'product_name': fields.char('Vendor Product Name', help="This vendor's product name will be used when printing a request for quotation. Keep empty to use the internal one."), 'product_code': fields.char('Vendor Product Code', help="This vendor's product code will be used when printing a request for quotation. Keep empty to use the internal one."), - 'sequence' : fields.integer('Sequence', help="Assigns the priority to the list of product vendor."), + 'sequence': fields.integer('Sequence', help="Assigns the priority to the list of product vendor."), 'product_uom': fields.related('product_tmpl_id', 'uom_po_id', type='many2one', relation='product.uom', string="Vendor Unit of Measure", readonly="1", help="This comes from the product form."), - 'min_qty': fields.float('Minimal Quantity', required=True, help="The minimal quantity to purchase to this vendor, expressed in the vendor Product Unit of Measure if not empty, in the default unit of measure of the product otherwise."), + 'min_qty': fields.float('Minimal Quantity', required=True, help="The minimal quantity to purchase from this vendor, expressed in the vendor Product Unit of Measure if not any, in the default unit of measure of the product otherwise."), 'qty': fields.function(_calc_qty, store=True, type='float', string='Quantity', multi="qty", help="This is a quantity which is converted into Default Unit of Measure."), - 'product_tmpl_id' : fields.many2one('product.template', 'Product Template', required=True, ondelete='cascade', select=True, oldname='product_id'), - 'delay' : fields.integer('Delivery Lead Time', required=True, help="Lead time in days between the confirmation of the purchase order and the receipt of the products in your warehouse. Used by the scheduler for automatic computation of the purchase order planning."), - 'pricelist_ids': fields.one2many('pricelist.partnerinfo', 'suppinfo_id', 'Vendor Pricelist', copy=True), - 'company_id':fields.many2one('res.company', string='Company',select=1), + 'price': fields.float('Price', required=True, digits_compute=dp.get_precision('Product Price'), help="The price to purchase a product"), + 'currency_id': fields.many2one('res.currency', 'Currency', required=True), + 'date_start': fields.date('Start Date', help="Start date for this vendor price"), + 'date_end': fields.date('End Date', help="End date for this vendor price"), + 'product_tmpl_id': fields.many2one('product.template', 'Product Template', ondelete='cascade', select=True, oldname='product_id'), + 'delay': fields.integer('Delivery Lead Time', required=True, help="Lead time in days between the confirmation of the purchase order and the receipt of the products in your warehouse. Used by the scheduler for automatic computation of the purchase order planning."), + 'company_id': fields.many2one('res.company', string='Company', select=1), } _defaults = { 'min_qty': 0.0, 'sequence': 1, 'delay': 1, - 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'product.supplierinfo', context=c), + 'price': 0.0, + 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'product.supplierinfo', context=c), + 'currency_id': lambda self, cr, uid, context: self.pool['res.users'].browse(cr, uid, uid, context=context).company_id.currency_id.id, } - _order = 'sequence' - - -class pricelist_partnerinfo(osv.osv): - _name = 'pricelist.partnerinfo' - _columns = { - 'name': fields.char('Description'), - 'suppinfo_id': fields.many2one('product.supplierinfo', 'Partner Information', required=True, ondelete='cascade'), - 'min_quantity': fields.float('Quantity', required=True, help="The minimal quantity to trigger this rule, expressed in the vendor Unit of Measure if any or in the default Unit of Measure of the product otherrwise."), - 'price': fields.float('Unit Price', required=True, digits_compute=dp.get_precision('Product Price'), help="This price will be considered as a price for the vendor Unit of Measure if any or the default Unit of Measure of the product otherwise"), - } - _order = 'min_quantity asc' class res_currency(osv.osv): _inherit = 'res.currency' diff --git a/addons/product/product_data.xml b/addons/product/product_data.xml index e24840ba489..058ec7ce5eb 100644 --- a/addons/product/product_data.xml +++ b/addons/product/product_data.xml @@ -182,48 +182,20 @@ parameter) will see those record just disappear. <field name="object">product.product</field> </record> - <!-- - Resource: product.price.type - --> - <record id="list_price" model="product.price.type"> - <field name="name">Public Price</field> - <field name="field">list_price</field> - </record> - <record id="standard_price" model="product.price.type"> - <field name="name">Vendor Section on Product or Cost Price</field> - <field name="field">standard_price</field> - </record> - - - - - <!-- - Price list type - --> - <record id="pricelist_type_sale" model="product.pricelist.type"> - <field name="name">Sale Pricelist</field> - <field name="key">sale</field> - </record> - + <!-- Price list --> - <!-- - Price list - --> <record id="list0" model="product.pricelist"> <field name="name">Public Pricelist</field> - <field name="type">sale</field> - </record> - <record id="ver0" model="product.pricelist.version"> - <field name="pricelist_id" ref="list0"/> - <field name="name">Default Public Pricelist Version</field> </record> + + <!-- Price list item --> + <record id="item0" model="product.pricelist.item"> - <field name="price_version_id" ref="ver0"/> - <field name="base" ref="list_price"/> + <field name="pricelist_id" ref="list0"/> + <field name="compute_price">formula</field> + <field name="base">list_price</field> <field name="sequence">1000</field> - <field name="name">Default Public Pricelist Line</field> </record> - <!-- Property --> diff --git a/addons/product/product_demo.xml b/addons/product/product_demo.xml index f69817a024f..494666cb7ba 100644 --- a/addons/product/product_demo.xml +++ b/addons/product/product_demo.xml @@ -891,6 +891,7 @@ QWERTY keyboard</field> <field name="name" ref="base.res_partner_1"/> <field name="delay">3</field> <field name="min_qty">1</field> + <field name="price">750</field> </record> <record id="product_supplierinfo_2" model="product.supplierinfo"> @@ -898,6 +899,15 @@ QWERTY keyboard</field> <field name="name" ref="base.res_partner_4"/> <field name="delay">3</field> <field name="min_qty">1</field> + <field name="price">790</field> + </record> + + <record id="product_supplierinfo_2bis" model="product.supplierinfo"> + <field name="product_tmpl_id" ref="product_product_6_product_template"/> + <field name="name" ref="base.res_partner_4"/> + <field name="delay">3</field> + <field name="min_qty">3</field> + <field name="price">785</field> </record> <record id="product_supplierinfo_3" model="product.supplierinfo"> diff --git a/addons/product/product_pricelist_demo.yml b/addons/product/product_pricelist_demo.yml index d7b3e329489..583eb806887 100644 --- a/addons/product/product_pricelist_demo.yml +++ b/addons/product/product_pricelist_demo.yml @@ -5,58 +5,38 @@ - !record {model: product.pricelist, id: customer_pricelist}: name: Customer Pricelist - type: sale - version_id: - - name: v1.0 - date_start: 2012-01-01 - items_id: - - name: Default pricelist - base: -1 - base_pricelist_id: list0 - - name: 10% Discount on Assemble Computer - sequence: 1 - product_id: product_product_4 - base: !eval (ref('product.list_price')) - price_discount: -0.10 - - name: 1 surchange on Laptop - sequence: 1 - product_id: product_product_25 - base: !eval (ref('product.list_price')) - price_surcharge: 1 - - name: 5% Discount on all Computer related products - sequence: 1 - min_quantity: 2 - base: !eval (ref('product.list_price')) - categ_id: product_category_5 - price_discount: -0.05 - - name: v2.0 (Special Discount on all products during last 5 days in current year) + item_ids: + - name: Default pricelist + compute_price: 'formula' + base: 'pricelist' + base_pricelist_id: list0 + - name: 10% Discount on Assemble Computer + applied_on : '1_product' + sequence: 1 + product_id: product_product_4 + compute_price: 'formula' + base: 'list_price' + price_discount: 10 + - name: 1 surchange on Laptop + applied_on : '1_product' + sequence: 1 + product_id: product_product_25 + compute_price: 'formula' + base: 'list_price' + price_surcharge: 1 + - name: 5% Discount on all Computer related products + applied_on : '2_product_category' + sequence: 1 + min_quantity: 2 + compute_price: 'formula' + base: 'list_price' + categ_id: product_category_5 + price_discount: 5 + - name: 30% Discount on all products + applied_on : '0_product_variant' date_start: 2011-12-27 date_end: 2011-12-31 - items_id: - - name: 30% Discount on all products - price_discount: -0.30 - sequence: 1 - base: !eval (ref('product.list_price')) -- - !record {model: product.pricelist, id: supplier_pricelist}: - name: Vendor Pricelist - type: sale - version_id: - - name: v1.0 - items_id: - - name: 20% Discount given by my supplier - sequence: 1 - price_min_margin: 2 - price_max_margin: 5 - product_id: product_product_6 - base: !eval (ref('product.standard_price')) -- - !record {model: pricelist.partnerinfo, id: supplier_pricelist0_product_pc2}: - suppinfo_id: product_supplierinfo_2 - min_quantity: 3 - price: 785 -- - !record {model: pricelist.partnerinfo, id: supplier_pricelist1_product_pc2}: - suppinfo_id: product_supplierinfo_2 - min_quantity: 1 - price: 790 + compute_price: 'formula' + price_discount: 30 + sequence: 1 + base: 'list_price' diff --git a/addons/product/product_view.xml b/addons/product/product_view.xml index 9cdaf667fce..e9adcad0d74 100644 --- a/addons/product/product_view.xml +++ b/addons/product/product_view.xml @@ -133,6 +133,19 @@ </group> </page> <page string="Sales" attrs="{'invisible':[('sale_ok','=',False)]}" name="sales"> + <div name="pricelist_item" groups="product.group_product_pricelist"> + <separator string="Pricing"/> + <field name="item_ids" nolabel="1" context="{'default_base':'list_price', 'default_applied_on' :'1'}"> + <tree string="Pricelist Items" editable="bottom"> + <field name="pricelist_id" string="Pricelist" required='1'/> + <field name="fixed_price" string="Price" required='1'/> + <field name="min_quantity"/> + <field name="date_start"/> + <field name="date_end"/> + <field name="applied_on" invisible="1"/> + </tree> + </field> + </div> <group name="sale"> <group name="sale_condition" string="Sale Conditions"> <label for="warranty"/> @@ -760,30 +773,33 @@ <field name="arch" type="xml"> <form string="Vendor Information"> <group> - <group> + <group string="Vendor"> <field name="name" context="{'default_customer': 0, 'search_default_supplier': 1, 'default_supplier': 1}"/> - <field name="min_qty"/> - <field name="product_uom" groups="product.group_uom"/> - <field name="delay"/> - </group><group> - <field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/> <field name="product_name"/> <field name="product_code"/> + <label for="delay"/> + <div> + <field name="delay" class="oe_inline"/> days + </div> + </group> + <group string="Price List"> + <field name="product_tmpl_id" string="Product" invisible="context.get('visible_product_tmpl_id', True)"/> + <label for="min_qty"/> + <div> + <field name="min_qty" class="oe_inline"/> + <field name="product_uom" class="oe_inline" groups="product.group_uom"/> + </div> + <label for="price"/> + <div> + <field name="price" class="oe_inline"/><field name="currency_id" class="oe_inline" groups="base.group_multi_currency"/> + </div> + <label for="date_start" string="Validity"/> + <div><field name="date_start" class="oe_inline"/> to <field name="date_end" class="oe_inline"/></div> + </group> + <group string="Other Information" groups="base.group_multi_company"> + <field name="company_id" options="{'no_create': True}"/> </group> </group> - <p groups="product.group_purchase_pricelist" class="oe_grey">The prices below will only be taken into account when your pricelist is set as based on vendor prices.</p> - <field groups="product.group_purchase_pricelist" name="pricelist_ids"> - <tree editable="bottom" string="Pricelist"> - <field name="min_quantity"/> - <field name="price"/> - </tree> - <form> - <group> - <field name="min_quantity"/> - <field name="price"/> - </group> - </form> - </field> </form> </field> </record> @@ -794,12 +810,23 @@ <tree string="Vendor Information"> <field name="sequence" widget="handle"/> <field name="name"/> - <field name="delay"/> + <field name="product_tmpl_id" string="Product" invisible="context.get('visible_product_tmpl_id', True)"/> <field name="min_qty"/> - <field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/> + <field name="price" string="Price"/> + <field name="date_start"/> + <field name="date_end"/> </tree> </field> </record> + <record id="product_supplierinfo_type_action" model="ir.actions.act_window"> + <field name="name">Supplier Pricelist</field> + <field name="type">ir.actions.act_window</field> + <field name="res_model">product.supplierinfo</field> + <field name="view_type">form</field> + <field name="view_mode">tree,form</field> + <field name="context">{'visible_product_tmpl_id':False}</field> + </record> + </data> </openerp> diff --git a/addons/product/security/ir.model.access.csv b/addons/product/security/ir.model.access.csv index e0f8e74c9dd..1b5efabf9d2 100644 --- a/addons/product/security/ir.model.access.csv +++ b/addons/product/security/ir.model.access.csv @@ -5,14 +5,9 @@ access_product_category_user,product.category.user,model_product_category,base.g access_product_template_user,product.template.user,model_product_template,base.group_user,1,0,0,0
access_product_packaging_user,product.packaging.user,model_product_packaging,base.group_user,1,0,0,0
access_product_supplierinfo_user,product.supplierinfo.user,model_product_supplierinfo,base.group_user,1,0,0,0
-access_pricelist_partnerinfo_user,pricelist.partnerinfo.user,model_pricelist_partnerinfo,base.group_user,1,0,0,0
-access_product_price_type_user,product.price.type.user,model_product_price_type,base.group_user,1,0,0,0
-access_product_pricelist_type_user,product.pricelist.type.user,model_product_pricelist_type,,1,0,0,0
access_product_pricelist_user,product.pricelist.user,model_product_pricelist,base.group_user,1,0,0,0
-access_product_pricelist_version_user,product.pricelist.version.user,model_product_pricelist_version,base.group_user,1,0,0,0
access_product_pricelist_item_user,product.pricelist.item.user,model_product_pricelist_item,base.group_user,1,0,0,0
access_product_pricelist_item_sale_manager,product.pricelist.item salemanager,product.model_product_pricelist_item,base.group_sale_manager,1,1,1,1
-access_product_pricelist_type_partner_manager,product.pricelist.type partner manager,model_product_pricelist_type,base.group_partner_manager,1,0,0,0
access_product_pricelist_partner_manager,product.pricelist partner manager,model_product_pricelist,base.group_partner_manager,1,0,0,0
access_product_product_employee,product.product employee,model_product_product,base.group_user,1,0,0,0
access_product_price_history_employee,prices.history employee,model_product_price_history,base.group_user,1,0,0,0
diff --git a/addons/product/security/product_security.xml b/addons/product/security/product_security.xml index 5f9fd770aa3..fef66424f61 100644 --- a/addons/product/security/product_security.xml +++ b/addons/product/security/product_security.xml @@ -7,8 +7,13 @@ <field name="category_id" ref="base.module_category_hidden"/> </record> - <record id="group_purchase_pricelist" model="res.groups"> - <field name="name">Purchase Pricelists</field> + <record id="group_pricelist_item" model="res.groups"> + <field name="name">Manage Pricelist Items</field> + <field name="category_id" ref="base.module_category_hidden"/> + </record> + + <record id="group_product_pricelist" model="res.groups"> + <field name="name">Pricelists On Product</field> <field name="category_id" ref="base.module_category_hidden"/> </record> @@ -62,13 +67,6 @@ <field name="domain_force"> ['|',('company_id','=',user.company_id.id),('company_id','=',False)]</field> </record> - <record model="ir.rule" id="product_pricelist_version_comp_rule"> - <field name="name">product pricelist version company rule</field> - <field name="model_id" ref="model_product_pricelist_version"/> - <field name="global" eval="True"/> - <field name="domain_force"> ['|',('company_id','=',user.company_id.id),('company_id','=',False)]</field> - </record> - <record model="ir.rule" id="product_supplierinfo_comp_rule"> <field name="name">product supplierinfo company rule</field> <field name="model_id" ref="model_product_supplierinfo"/> diff --git a/addons/product/test/product_pricelist.yml b/addons/product/test/product_pricelist.yml index 6380e660451..1857151e843 100644 --- a/addons/product/test/product_pricelist.yml +++ b/addons/product/test/product_pricelist.yml @@ -51,9 +51,9 @@ - !python {model: product.product}: | from openerp.tools import float_compare - context.update({'quantity':1, 'date': False, 'partner': ref('base.res_partner_4'), 'pricelist': ref("supplier_pricelist")}) + context.update({'quantity':1, 'date': False, 'partner': ref('base.res_partner_4')}) product = self.browse(cr, uid, ref("product_product_6"), context=context) - assert float_compare(product.price, 792, precision_digits=2) == 0, "Wrong cost price: LCD Monitor." + assert float_compare(product.seller_price, 790, precision_digits=2) == 0, "Wrong cost price: LCD Monitor." - I check cost price of LCD Monitor if more than 3 Unit. - @@ -61,7 +61,7 @@ from openerp.tools import float_compare context.update({'quantity':3}) product = self.browse(cr, uid, ref("product_product_6"), context=context) - assert float_compare(product.price, 787, precision_digits=2) == 0, "Wrong cost price: LCD Monitor if more than 3 Unit." + assert float_compare(product.seller_price, 785, precision_digits=2) == 0, "Wrong cost price: LCD Monitor if more than 3 Unit." - I print the sale prices report. - diff --git a/addons/product/tests/test_pricelist.py b/addons/product/tests/test_pricelist.py index dc2b4852e7c..3e9cd7ee3c8 100644 --- a/addons/product/tests/test_pricelist.py +++ b/addons/product/tests/test_pricelist.py @@ -21,21 +21,19 @@ class TestPricelist(TransactionCase): self.public_pricelist_id = self.ir_model_data.get_object_reference(cr, uid, 'product', 'list0')[1] self.sale_pricelist_id = self.product_pricelist.create(cr, uid, { 'name': 'Sale pricelist', - 'type': 'sale', - 'version_id': [(0, 0, { - 'name': 'v1.0', - 'items_id': [(0, 0, { - 'name': 'Discount 10%', - 'base': 1, # based on public price - 'price_discount': -0.1, - 'product_id': self.usb_adapter_id + 'item_ids': [(0, 0, { + 'compute_price': 'formula', + 'base': 'list_price', # based on public price + 'price_discount': 10, + 'product_id': self.usb_adapter_id, + 'applied_on': '0_product_variant', }), (0, 0, { - 'name': 'Discount -0.5', - 'base': 1, # based on public price + 'compute_price': 'formula', + 'base': 'list_price', # based on public price 'price_surcharge': -0.5, - 'product_id': self.datacard_id + 'product_id': self.datacard_id, + 'applied_on': '0_product_variant', })] - })] }, context=context) def test_10_discount(self): @@ -80,7 +78,6 @@ class TestPricelist(TransactionCase): # make sure 'tonne' resolves down to 1 'kg'. self.uom.write(cr, uid, tonne, {'rounding': 0.001}) - # setup product stored in 'tonnes', with a discounted pricelist for qty > 3 tonnes spam_id = self.product_product.copy(cr, uid, self.usb_adapter_id, { 'name': '1 tonne of spam', @@ -89,16 +86,15 @@ class TestPricelist(TransactionCase): 'list_price': tonne_price, 'type': 'consu', }) - pricelist_version_id = self.ir_model_data.xmlid_to_res_id(cr, uid, 'product.ver0') - self.registry('product.pricelist.item').create(cr, uid, - { 'price_version_id': pricelist_version_id, - 'sequence': 10, - 'name': '3+ tonnes: -10 EUR discount/t', - 'base': 1, # based on public price - 'min_quantity': 3, # min = 3 tonnes - 'price_surcharge': -10, # -10 EUR / tonne - 'product_id': spam_id, - }) + self.registry('product.pricelist.item').create(cr, uid, { + 'pricelist_id': self.public_pricelist_id, + 'sequence': 10, + 'applied_on': '0_product_variant', + 'compute_price': 'formula', + 'base': 'list_price', # based on public price + 'min_quantity': 3, # min = 3 tonnes + 'price_surcharge': -10, # -10 EUR / tonne + 'product_id': spam_id, }) pricelist_id = self.public_pricelist_id def test_unit_price(qty, uom, expected_unit_price): |
