Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 42 additions & 12 deletions product_uom_prices/sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
19 changes: 10 additions & 9 deletions purchase_uom_prices_uoms/purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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}
Expand Down
8 changes: 8 additions & 0 deletions sale_stock_product_uom_prices/__init__.py
Original file line number Diff line number Diff line change
@@ -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:
44 changes: 44 additions & 0 deletions sale_stock_product_uom_prices/__openerp__.py
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'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:
28 changes: 28 additions & 0 deletions sale_stock_product_uom_prices/sale.py
Original file line number Diff line number Diff line change
@@ -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