diff --git a/product_uom_prices/sale.py b/product_uom_prices/sale.py index eebb6d1f..6413d0a0 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): @@ -23,31 +23,61 @@ 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): + # 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( - 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) 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 + ): + uom_id = product.uom_price_ids[0].uom_id.id res['value'].update( - {'product_uom': product.uom_price_ids[0].uom_id.id}) + {'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}) # 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 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..0214ff9a --- /dev/null +++ b/sale_stock_product_uom_prices/__openerp__.py @@ -0,0 +1,44 @@ +# -*- 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': [ + ], + '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..bfd38e14 --- /dev/null +++ b/sale_stock_product_uom_prices/sale.py @@ -0,0 +1,28 @@ +# -*- 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): + 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) + return res