1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2011 MSF, TeMPO consulting
#
# 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/>.
#
##############################################################################
from osv import osv
from tools.translate import _
class purchase_order_line(osv.osv):
_name = 'purchase.order.line'
_inherit = 'purchase.order.line'
def _hook_product_id_change(self, cr, uid, *args, **kwargs):
'''
Override the computation of product qty to order
'''
product_id = kwargs['product']
partner_id = kwargs['partner_id']
product_qty = kwargs['product_qty']
pricelist = kwargs['pricelist']
order_date = kwargs['order_date']
product_uom_id = kwargs['uom_id']
seller_delay = kwargs['seller_delay']
context = kwargs['context']
res = kwargs['res']
partner_price = self.pool.get('pricelist.partnerinfo')
suppinfo_obj = self.pool.get('product.supplierinfo')
prod_obj = self.pool.get('product.product')
catalogue_obj = self.pool.get('supplier.catalogue')
currency_id = self.pool.get('product.pricelist').browse(cr, uid, pricelist, context=context).currency_id.id
info_prices = []
domain = [('min_quantity', '<=', product_qty),
('uom_id', '=', product_uom_id),
('partner_id', '=', partner_id),
('product_id', '=', product_id.product_tmpl_id.id),
'|', ('valid_from', '<=', order_date),
('valid_from', '=', False),
'|', ('valid_till', '>=', order_date),
('valid_till', '=', False)]
domain_cur = [('currency_id', '=', currency_id)]
domain_cur.extend(domain)
info_prices = partner_price.search(cr, uid, domain_cur, order='sequence asc, min_quantity asc, id desc', limit=1, context=context)
if not info_prices:
info_prices = partner_price.search(cr, uid, domain, order='sequence asc, min_quantity asc, id desc', limit=1, context=context)
if info_prices:
# info = partner_price.browse(cr, uid, info_price, context=context)[0]
info = partner_price.browse(cr, uid, info_prices[0], context=context)
seller_delay = info.suppinfo_id.delay
if info.min_order_qty and product_qty < info.min_order_qty:
product_qty = info.min_order_qty
res.update({'warning': {'title': _('Warning'), 'message': _('The product unit price has been set for a minimal quantity of %s '\
'(the min quantity of the price list), it might change at the '\
'supplier confirmation.') % product_qty}})
if info.rounding and product_qty%info.rounding != 0:
if not res.get('warning', {}).get('message', False):
res.update({'warning': {'title': _('Warning'), 'message': _('The selected supplier has a packaging ' \
'which is a multiple of %s.') % info.rounding}})
product_qty = product_qty + (info.rounding - product_qty%info.rounding)
return res, product_qty, product_qty, seller_delay
purchase_order_line()
|