From 2312dc5651c0190824f54f52af424d51e17c585f Mon Sep 17 00:00:00 2001 From: Juan Jose Scarafia Date: Mon, 11 Jan 2016 13:56:38 -0300 Subject: [PATCH 1/4] IMP use new api --- product_uom_prices/sale.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/product_uom_prices/sale.py b/product_uom_prices/sale.py index eebb6d1f..b60bfbb9 100644 --- a/product_uom_prices/sale.py +++ b/product_uom_prices/sale.py @@ -23,31 +23,42 @@ def _get_units(self): def get_product_uoms(self, product): return product.uom_price_ids.mapped('uom_id') + product.uom_id + @api.multi def product_id_change( - self, cr, uid, ids, pricelist, product, qty=0, + self, pricelist, product, qty=0, uom=False, qty_uos=0, uos=False, name='', partner_id=False, lang=False, update_tax=True, date_order=False, packaging=False, - fiscal_position=False, flag=False, context=None): + fiscal_position=False, flag=False): res = super(sale_order_line, self).product_id_change( - cr, uid, ids, pricelist, product, qty=qty, uom=uom, + pricelist, product, qty=qty, uom=uom, qty_uos=qty_uos, uos=uos, name=name, partner_id=partner_id, lang=lang, update_tax=update_tax, date_order=date_order, packaging=packaging, fiscal_position=fiscal_position, - flag=flag, context=context) + flag=flag) + print 'res uom prices', res if product: context_partner = {'lang': lang, 'partner_id': partner_id} - product_obj = self.pool.get('product.product') - user = self.pool.get('res.users').browse(cr, uid, uid) - product = product_obj.browse( - cr, uid, product, context=context_partner) - if not uom and product.use_uom_prices and user.company_id.default_uom_prices: + product = self.env['product.product'].with_context( + context_partner).browse( + product) + if ( + not uom and product.use_uom_prices and + self.env.user.company_id.default_uom_prices + ): res['value'].update( {'product_uom': product.uom_price_ids[0].uom_id.id}) + res2 = super(sale_order_line, self).product_id_change( + pricelist, product, qty=qty, uom=uom, + qty_uos=qty_uos, uos=uos, name=name, partner_id=partner_id, + lang=lang, update_tax=update_tax, date_order=date_order, + packaging=packaging, fiscal_position=fiscal_position, + flag=flag) + print 'res22 uom prices', res2 # we do this because odoo overwrite view domain if 'domain' not in res: res['domain'] = {} res['domain']['product_uom'] = [ ('id', 'in', self.get_product_uoms( - cr, uid, product, context=context).ids)] + product).ids)] return res From f8d4c558c4eb61544cfeb19810eeb4e4a5552ad8 Mon Sep 17 00:00:00 2001 From: Juan Jose Scarafia Date: Mon, 11 Jan 2016 17:28:00 -0300 Subject: [PATCH 2/4] FIX --- product_uom_prices/sale.py | 39 +++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/product_uom_prices/sale.py b/product_uom_prices/sale.py index b60bfbb9..48450022 100644 --- a/product_uom_prices/sale.py +++ b/product_uom_prices/sale.py @@ -3,7 +3,7 @@ # For copyright and license notices, see __openerp__.py file in module root # directory ############################################################################## -from openerp import models, fields, api +from openerp import models, fields, api, SUPERUSER_ID class sale_order_line(models.Model): @@ -46,15 +46,36 @@ def product_id_change( not uom and product.use_uom_prices and self.env.user.company_id.default_uom_prices ): + uom_id = product.uom_price_ids[0].uom_id.id res['value'].update( - {'product_uom': product.uom_price_ids[0].uom_id.id}) - res2 = super(sale_order_line, self).product_id_change( - pricelist, product, qty=qty, uom=uom, - qty_uos=qty_uos, uos=uos, name=name, partner_id=partner_id, - lang=lang, update_tax=update_tax, date_order=date_order, - packaging=packaging, fiscal_position=fiscal_position, - flag=flag) - print 'res22 uom prices', res2 + {'product_uom': uom_id}) + # res2 = super(sale_order_line, self).product_id_change( + # pricelist, product.id, qty=qty, uom=uom, + # qty_uos=qty_uos, uos=uos, name=name, partner_id=partner_id, + # lang=lang, update_tax=update_tax, date_order=date_order, + # packaging=packaging, fiscal_position=fiscal_position, + # flag=flag) + # si tenemos instalado el modulo "sale_stock", entonces odoo por defecto + # hace un hack y borrar la uom elegida y a uom y precio por defecto del producto + # en nuestro caso entonces termina quedando mal porque cambiamos la uom pero no el precio + # por eso forzamos el recalculo del precio + price = self.env['product.pricelist'].browse( + pricelist).with_context( + uom=uom_id, date=date_order,).price_get( + product.id, qty or 1.0, partner_id)[pricelist] + if price: + if self.env.uid == SUPERUSER_ID and self._context.get( + 'company_id'): + taxes = product.taxes_id.filtered( + lambda r: r.company_id.id == self._context[ + 'company_id']) + else: + taxes = product.taxes_id + price = self.env['account.tax']._fix_tax_included_price( + price, taxes, result['tax_id']) + res['value'].update({'price_unit': price}) + print 'price', price + # print 'res22 uom prices', res2 # we do this because odoo overwrite view domain if 'domain' not in res: res['domain'] = {} From 9100280d2501bd48930eadf2f103c7ff05d3f59b Mon Sep 17 00:00:00 2001 From: Juan Jose Scarafia Date: Thu, 14 Jan 2016 11:19:05 -0300 Subject: [PATCH 3/4] USER preserve and new module sale stock product uom --- product_uom_prices/sale.py | 26 +++++----- purchase_uom_prices_uoms/purchase.py | 19 +++---- sale_stock_product_uom_prices/__init__.py | 8 +++ sale_stock_product_uom_prices/__openerp__.py | 45 +++++++++++++++++ sale_stock_product_uom_prices/sale.py | 49 +++++++++++++++++++ .../view/sale_view.xml | 15 ++++++ 6 files changed, 138 insertions(+), 24 deletions(-) create mode 100644 sale_stock_product_uom_prices/__init__.py create mode 100644 sale_stock_product_uom_prices/__openerp__.py create mode 100644 sale_stock_product_uom_prices/sale.py create mode 100644 sale_stock_product_uom_prices/view/sale_view.xml diff --git a/product_uom_prices/sale.py b/product_uom_prices/sale.py index 48450022..806b3a60 100644 --- a/product_uom_prices/sale.py +++ b/product_uom_prices/sale.py @@ -29,6 +29,10 @@ def product_id_change( uom=False, qty_uos=0, uos=False, name='', partner_id=False, lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False): + # because sale_stock module delete uom when colling this method, we + # add it in context con module 'sale_stock_product_uom_prices' + if not uom: + uom = self._context.get('preserve_uom', False) res = super(sale_order_line, self).product_id_change( pricelist, product, qty=qty, uom=uom, qty_uos=qty_uos, uos=uos, name=name, partner_id=partner_id, @@ -36,7 +40,6 @@ def product_id_change( packaging=packaging, fiscal_position=fiscal_position, flag=flag) - print 'res uom prices', res if product: context_partner = {'lang': lang, 'partner_id': partner_id} product = self.env['product.product'].with_context( @@ -49,16 +52,11 @@ def product_id_change( uom_id = product.uom_price_ids[0].uom_id.id res['value'].update( {'product_uom': uom_id}) - # res2 = super(sale_order_line, self).product_id_change( - # pricelist, product.id, qty=qty, uom=uom, - # qty_uos=qty_uos, uos=uos, name=name, partner_id=partner_id, - # lang=lang, update_tax=update_tax, date_order=date_order, - # packaging=packaging, fiscal_position=fiscal_position, - # flag=flag) - # si tenemos instalado el modulo "sale_stock", entonces odoo por defecto - # hace un hack y borrar la uom elegida y a uom y precio por defecto del producto - # en nuestro caso entonces termina quedando mal porque cambiamos la uom pero no el precio - # por eso forzamos el recalculo del precio + # si tenemos instalado el modulo "sale_stock", entonces odoo + # por defecto hace un hack y borrar la uom elegida y a uom y + # precio por defecto del producto en nuestro caso entonces + # termina quedando mal porque cambiamos la uom pero no el + # precio por eso forzamos el recalculo del precio price = self.env['product.pricelist'].browse( pricelist).with_context( uom=uom_id, date=date_order,).price_get( @@ -68,14 +66,12 @@ def product_id_change( 'company_id'): taxes = product.taxes_id.filtered( lambda r: r.company_id.id == self._context[ - 'company_id']) + 'company_id']) else: taxes = product.taxes_id price = self.env['account.tax']._fix_tax_included_price( - price, taxes, result['tax_id']) + price, taxes, res.get('value').get('tax_id')) res['value'].update({'price_unit': price}) - print 'price', price - # print 'res22 uom prices', res2 # we do this because odoo overwrite view domain if 'domain' not in res: res['domain'] = {} diff --git a/purchase_uom_prices_uoms/purchase.py b/purchase_uom_prices_uoms/purchase.py index 8fb19bca..709a2745 100644 --- a/purchase_uom_prices_uoms/purchase.py +++ b/purchase_uom_prices_uoms/purchase.py @@ -3,7 +3,7 @@ # For copyright and license notices, see __openerp__.py file in module root # directory ############################################################################## -from openerp import models +from openerp import models, api class purchase_order_line(models.Model): @@ -12,15 +12,16 @@ class purchase_order_line(models.Model): _inherit = 'purchase.order.line' - def onchange_product_id(self, cr, uid, ids, pricelist_id, product_id, qty, uom_id, - partner_id, date_order=False, fiscal_position_id=False, date_planned=False, - name=False, price_unit=False, state='draft', context=None): + @api.multi + def onchange_product_id( + self, pricelist_id, product_id, qty, uom_id, partner_id, + date_order=False, fiscal_position_id=False, date_planned=False, + name=False, price_unit=False, state='draft'): res = super(purchase_order_line, self).onchange_product_id( - cr, uid, ids, pricelist_id, product_id, qty=qty, uom_id=uom_id, - name=name, partner_id=partner_id, - date_order=date_order, price_unit=price_unit, - fiscal_position_id=fiscal_position_id, - date_planned=date_planned, state=state, context=context) + pricelist_id, product_id, qty=qty, uom_id=uom_id, name=name, + partner_id=partner_id, date_order=date_order, + price_unit=price_unit, fiscal_position_id=fiscal_position_id, + date_planned=date_planned, state=state) if product_id: context_partner = {'partner_id': partner_id} diff --git a/sale_stock_product_uom_prices/__init__.py b/sale_stock_product_uom_prices/__init__.py new file mode 100644 index 00000000..c376ca1f --- /dev/null +++ b/sale_stock_product_uom_prices/__init__.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +############################################################################## +# For copyright and license notices, see __openerp__.py file in module root +# directory +############################################################################## +from . import sale + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/sale_stock_product_uom_prices/__openerp__.py b/sale_stock_product_uom_prices/__openerp__.py new file mode 100644 index 00000000..82ffaeef --- /dev/null +++ b/sale_stock_product_uom_prices/__openerp__.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2015 ADHOC SA (http://www.adhoc.com.ar) +# All Rights Reserved. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + 'name': 'Sale Stock Product UOM Prices Integration', + 'version': '8.0.0.0.0', + 'category': 'base.module_category_knowledge_management', + 'description': """ +Sale Stock Product UOM Prices Integration +========================================= +""", + 'author': 'ADHOC SA.', + 'website': 'www.adhoc.com.ar', + 'license': 'AGPL-3', + 'depends': [ + 'sale_stock', + 'product_uom_prices', + ], + 'test': [], + 'demo': [], + 'data': [ + 'view/sale_view.xml', + ], + 'installable': True, + 'auto_install': True, + } + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/sale_stock_product_uom_prices/sale.py b/sale_stock_product_uom_prices/sale.py new file mode 100644 index 00000000..539a590e --- /dev/null +++ b/sale_stock_product_uom_prices/sale.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +############################################################################## +# For copyright and license notices, see __openerp__.py file in module root +# directory +############################################################################## +from openerp import models, api + + +class sale_order_line(models.Model): + + """""" + + _inherit = 'sale.order.line' + + @api.multi + def product_id_change_with_wh( + self, pricelist, product, qty=0, + uom=False, qty_uos=0, uos=False, name='', partner_id=False, + lang=False, update_tax=True, date_order=False, packaging=False, + fiscal_position=False, flag=False, warehouse_id=False): + # if uom: + # context + res = super(sale_order_line, self.with_context( + preserve_uom=uom)).product_id_change_with_wh( + pricelist, product, qty=qty, uom=uom, + qty_uos=qty_uos, uos=uos, name=name, partner_id=partner_id, + lang=lang, update_tax=update_tax, date_order=date_order, + packaging=packaging, fiscal_position=fiscal_position, + flag=flag, warehouse_id=warehouse_id) + + # print 'res1', res + # if product: + # context_partner = {'lang': lang, 'partner_id': partner_id} + # product = self.env['product.product'].with_context( + # context_partner).browse( + # product) + # if ( + # not uom and product.use_uom_prices and + # self.env.user.company_id.default_uom_prices + # ): + # res['value'].update( + # {'product_uom': product.uom_price_ids[0].uom_id.id}) + # # we do this because odoo overwrite view domain + # if 'domain' not in res: + # res['domain'] = {} + # res['domain']['product_uom'] = [ + # ('id', 'in', self.get_product_uoms( + # product).ids)] + return res diff --git a/sale_stock_product_uom_prices/view/sale_view.xml b/sale_stock_product_uom_prices/view/sale_view.xml new file mode 100644 index 00000000..5671b1be --- /dev/null +++ b/sale_stock_product_uom_prices/view/sale_view.xml @@ -0,0 +1,15 @@ + + + + + sale.order.form + sale.order + + + + {'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'uom':product_uom, 'company_id': parent.company_id, 'change_qty': True} + + + + + From 77b11f7c72b716bf932573defd2b7c393b194c09 Mon Sep 17 00:00:00 2001 From: Juan Jose Scarafia Date: Thu, 14 Jan 2016 11:24:11 -0300 Subject: [PATCH 4/4] IMP code of uom prices --- product_uom_prices/sale.py | 32 ++++++++++--------- sale_stock_product_uom_prices/__openerp__.py | 1 - sale_stock_product_uom_prices/sale.py | 21 ------------ .../view/sale_view.xml | 15 --------- 4 files changed, 17 insertions(+), 52 deletions(-) delete mode 100644 sale_stock_product_uom_prices/view/sale_view.xml diff --git a/product_uom_prices/sale.py b/product_uom_prices/sale.py index 806b3a60..6413d0a0 100644 --- a/product_uom_prices/sale.py +++ b/product_uom_prices/sale.py @@ -52,26 +52,28 @@ def product_id_change( uom_id = product.uom_price_ids[0].uom_id.id res['value'].update( {'product_uom': uom_id}) + + # TODO REMOVE. we leave all this just in case we need # si tenemos instalado el modulo "sale_stock", entonces odoo # por defecto hace un hack y borrar la uom elegida y a uom y # precio por defecto del producto en nuestro caso entonces # termina quedando mal porque cambiamos la uom pero no el # precio por eso forzamos el recalculo del precio - price = self.env['product.pricelist'].browse( - pricelist).with_context( - uom=uom_id, date=date_order,).price_get( - product.id, qty or 1.0, partner_id)[pricelist] - if price: - if self.env.uid == SUPERUSER_ID and self._context.get( - 'company_id'): - taxes = product.taxes_id.filtered( - lambda r: r.company_id.id == self._context[ - 'company_id']) - else: - taxes = product.taxes_id - price = self.env['account.tax']._fix_tax_included_price( - price, taxes, res.get('value').get('tax_id')) - res['value'].update({'price_unit': price}) + # price = self.env['product.pricelist'].browse( + # pricelist).with_context( + # uom=uom_id, date=date_order,).price_get( + # product.id, qty or 1.0, partner_id)[pricelist] + # if price: + # if self.env.uid == SUPERUSER_ID and self._context.get( + # 'company_id'): + # taxes = product.taxes_id.filtered( + # lambda r: r.company_id.id == self._context[ + # 'company_id']) + # else: + # taxes = product.taxes_id + # price = self.env['account.tax']._fix_tax_included_price( + # price, taxes, res.get('value').get('tax_id')) + # res['value'].update({'price_unit': price}) # we do this because odoo overwrite view domain if 'domain' not in res: res['domain'] = {} diff --git a/sale_stock_product_uom_prices/__openerp__.py b/sale_stock_product_uom_prices/__openerp__.py index 82ffaeef..0214ff9a 100644 --- a/sale_stock_product_uom_prices/__openerp__.py +++ b/sale_stock_product_uom_prices/__openerp__.py @@ -36,7 +36,6 @@ 'test': [], 'demo': [], 'data': [ - 'view/sale_view.xml', ], 'installable': True, 'auto_install': True, diff --git a/sale_stock_product_uom_prices/sale.py b/sale_stock_product_uom_prices/sale.py index 539a590e..bfd38e14 100644 --- a/sale_stock_product_uom_prices/sale.py +++ b/sale_stock_product_uom_prices/sale.py @@ -18,8 +18,6 @@ def product_id_change_with_wh( uom=False, qty_uos=0, uos=False, name='', partner_id=False, lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False, warehouse_id=False): - # if uom: - # context res = super(sale_order_line, self.with_context( preserve_uom=uom)).product_id_change_with_wh( pricelist, product, qty=qty, uom=uom, @@ -27,23 +25,4 @@ def product_id_change_with_wh( lang=lang, update_tax=update_tax, date_order=date_order, packaging=packaging, fiscal_position=fiscal_position, flag=flag, warehouse_id=warehouse_id) - - # print 'res1', res - # if product: - # context_partner = {'lang': lang, 'partner_id': partner_id} - # product = self.env['product.product'].with_context( - # context_partner).browse( - # product) - # if ( - # not uom and product.use_uom_prices and - # self.env.user.company_id.default_uom_prices - # ): - # res['value'].update( - # {'product_uom': product.uom_price_ids[0].uom_id.id}) - # # we do this because odoo overwrite view domain - # if 'domain' not in res: - # res['domain'] = {} - # res['domain']['product_uom'] = [ - # ('id', 'in', self.get_product_uoms( - # product).ids)] return res diff --git a/sale_stock_product_uom_prices/view/sale_view.xml b/sale_stock_product_uom_prices/view/sale_view.xml deleted file mode 100644 index 5671b1be..00000000 --- a/sale_stock_product_uom_prices/view/sale_view.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - sale.order.form - sale.order - - - - {'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'uom':product_uom, 'company_id': parent.company_id, 'change_qty': True} - - - - -