~pexego/openobject-addons/6.1-pexego-new-addons

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
# -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2012 Pexego S.L. (<http://www.pexego.es>).
#
#    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/>.
#
##############################################################################
import time
from lxml import etree
import decimal_precision as dp

from osv import fields, osv, orm
from tools.translate import _



class account_invoice(osv.osv):
    _inherit = 'account.invoice'
    _columns = {
        'recalculate_cost_price': fields.boolean('Recalculate product costs', help="If checked the system will compare the prices of invoices with the delivery note and if there are differences recalculate the cost price "),
    }
    
    def action_move_create(self, cr, uid, ids, *args):
        """Check if the price is different, if so it creates the account move and regenerate PMP """
                
        ret = super(account_invoice, self).action_move_create(cr, uid, ids, *args)
        if ret:
            #===================================================================
            # cur_obj = self.pool.get('res.currency')
            # period_obj = self.pool.get('account.period')
            # journal_obj = self.pool.get('account.journal')
            # move_obj = self.pool.get('account.move')
            # move_line_obj = self.pool.get('account.move.line')
            # picking_obj = self.pool.get('stock.picking')
            #===================================================================
            for inv in self.browse(cr, uid, ids):   
                if inv.recalculate_cost_price == True:
                    for line in inv.invoice_line:
                        if line.stock_move_id:
                            if (line.stock_move_id.picking_id.type == 'in') and (line.stock_move_id.product_id.cost_method == 'average'):
                                #TODO: Hay que revisar el tema de las unidades de medida y divisas que no se está considerando
                                if (line.stock_move_id.price_unit != line.price_unit):
                                    line.stock_move_id.recalculate_pmp (line.price_unit, line.uos_id, line.quantity)

        return ret
	

account_invoice ()