~vauxoo/addons-vauxoo/6.0-trunk

« back to all changes in this revision

Viewing changes to report_profit/product.py

  • Committer: Javier Duran
  • Author(s): javier at vauxoo
  • Date: 2012-02-28 19:37:10 UTC
  • Revision ID: javier@squezee-vir-20120228193710-f1270gs5o8yzoxx4
[ADD] Se agregan campos y metodos al modelo producto para el calculo del último costo al cual se compró el produco,
así como la factura y fecha asociada al mismo, en el modulo report_profit

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
import ir
35
35
import pooler
36
36
import time
37
 
from tools import config
 
37
import decimal_precision as dp
38
38
 
39
39
class product_supplierinfo(osv.osv):
40
40
    _inherit = 'product.supplierinfo'
43
43
    def _last_sup_invoice(self, cr, uid, ids, name, arg, context):
44
44
        res = {}
45
45
        for supinfo in self.browse(cr, uid, ids):
46
 
            cr.execute("select inv.id, max(inv.date_invoice) from account_invoice as inv, account_invoice_line as line where inv.id=line.invoice_id and product_id=%s and partner_id=%s and state in ('open', 'paid') and type='in_invoice' group by inv.id", (supinfo.product_id.id, supinfo.name.id,))
 
46
            cr.execute("select inv.id, max(inv.date_invoice) from account_invoice as inv, account_invoice_line as line where inv.id=line.invoice_id and product_id=%s and inv.partner_id=%s and state in ('open', 'paid') and type='in_invoice' group by inv.id", (supinfo.product_id.id, supinfo.name.id,))
47
47
            record = cr.fetchone()
48
48
            if record:
49
49
                res[supinfo.id] = record[0]
65
65
        return res
66
66
 
67
67
    _columns = {
68
 
        'last_inv' : fields.function(_last_sup_invoice, type='many2one', obj='account.invoice', method=True, string='Last Invoice'),
 
68
        'last_inv' : fields.function(_last_sup_invoice, type='many2one', relation='account.invoice', method=True, string='Last Invoice'),
69
69
        'last_inv_date' : fields.function(_last_sup_invoice_date, type='date', method=True, string='Last Invoice date'),
70
70
    }
71
71
product_supplierinfo()
100
100
 
101
101
 
102
102
    def _get_last_invoice_price_func(states, what):
103
 
        
104
103
        def _last_invoice_price(self, cr, uid, ids, name, arg, context):
105
104
            return self._product_get_price(cr, uid, ids, False, False, False, context, states, what)
106
105
        return _last_invoice_price
131
130
        states_str = ','.join(map(lambda s: "'%s'" % s, states))
132
131
        date = date_ref or time.strftime('%Y-%m-%d')
133
132
        if ids[0]:
134
 
            print 'ids: ',ids
135
 
            print 'self.browse(cr, uid, ids): ',self.browse(cr, uid, ids)
136
133
            for product in self.browse(cr, uid, ids):
137
134
                sql = "select inv.id, max(inv.date_invoice) as date from account_invoice as inv, account_invoice_line as line where inv.id=line.invoice_id and product_id=%s and state in (%s) and type='%s' and date_invoice<='%s' group by inv.id order by date desc" % (product.id,states_str,what,date)
138
135
                if supplier_id:
139
 
                    sql = "select inv.id, max(inv.date_invoice) as date from account_invoice as inv, account_invoice_line as line where inv.id=line.invoice_id and product_id=%s and partner_id=%s and state in (%s) and type='%s' and date_invoice<='%s' group by inv.id order by date desc" % (product.id,supplier_id,states_str,what,date)
 
136
                    sql = "select inv.id, max(inv.date_invoice) as date from account_invoice as inv, account_invoice_line as line where inv.id=line.invoice_id and product_id=%s and inv.partner_id=%s and state in (%s) and type='%s' and date_invoice<='%s' group by inv.id order by date desc" % (product.id,supplier_id,states_str,what,date)
140
137
 
141
138
                cr.execute(sql)
142
139
                allrecord = cr.fetchall()
143
 
                record = allrecord and allrecord.pop(0) or False                
 
140
                record = allrecord and allrecord.pop(0) or False
144
141
                if invoice_id and record and record[0]==invoice_id:
145
142
                    record = allrecord and allrecord.pop(0) or False
146
143
                if record:
158
155
    _columns = {
159
156
        'last_pur_inv' : fields.function(_pur_inv, type='many2one', obj='account.invoice', method=True, string='Last Purchase Invoice'),
160
157
        'last_pur_inv_date' : fields.function(_pur_inv_date, type='date', method=True, string='Last Purchase Invoice date'),
161
 
        'last_cost': fields.function(_pur_inv_cost, type="float", method=True, string='Last Cost', digits=(16, int(config['price_accuracy']))),
 
158
        'last_cost': fields.function(_pur_inv_cost, type="float", method=True, string='Last Cost', digits_compute= dp.get_precision('Account')),
162
159
    }
163
160
 
164
161
product_product()