Change invoiced field in function

bzr revid: ced-577e5bb99c50a146554f9a4249a322d08d312c94
This commit is contained in:
ced 2007-10-24 06:13:46 +00:00
parent 259e5b943b
commit 648d08dc71
2 changed files with 45 additions and 8 deletions

View File

@ -60,7 +60,6 @@ class sale_order(osv.osv):
default.update({
'state':'draft',
'shipped':False,
'invoiced':False,
'invoice_ids':[],
'picking_ids':[],
'name': self.pool.get('ir.sequence').get(cr, uid, 'sale.order'),
@ -101,6 +100,47 @@ class sale_order(osv.osv):
res[id] = cur_obj.round(cr, uid, cur, untax.get(id, 0.0) + tax.get(id, 0.0))
return res
def _invoiced(self, cursor, user, ids, name, arg, context=None):
res = {}
for sale in self.browse(cursor, user, ids, context=context):
res[sale.id] = True
for invoice in sale.invoice_ids:
if invoice.state <> 'paid':
res[sale.id] = False
break
if not sale.invoice_ids:
res[sale.id] = False
return res
def _invoiced_search(self, cursor, user, obj, name, args):
if not len(args):
return []
clause = ''
no_invoiced = False
for arg in args:
if arg[1] == '=':
if arg[2]:
clause += 'AND inv.state = \'paid\''
else:
clause += 'AND inv.state <> \'paid\''
no_invoiced = True
cursor.execute('SELECT rel.order_id ' \
'FROM sale_order_invoice_rel AS rel, account_invoice AS inv ' \
'WHERE rel.invoice_id = inv.id ' + clause)
res = cursor.fetchall()
if no_invoiced:
cursor.execute('SELECT sale.id ' \
'FROM sale_order AS sale ' \
'WHERE sale.id NOT IN ' \
'(SELECT rel.order_id ' \
'FROM sale_order_invoice_rel AS rel)')
res.extend(cursor.fetchall())
if not res:
return [('id', '=', 0)]
return [('id', 'in', [x[0] for x in res])]
_columns = {
'name': fields.char('Order Description', size=64, required=True, select=True),
'shop_id':fields.many2one('sale.shop', 'Shop', required=True, readonly=True, states={'draft':[('readonly',False)]}),
@ -144,12 +184,10 @@ class sale_order(osv.osv):
'order_line': fields.one2many('sale.order.line', 'order_id', 'Order Lines', readonly=True, states={'draft':[('readonly',False)]}),
'invoice_ids': fields.many2many('account.invoice', 'sale_order_invoice_rel', 'order_id', 'invoice_id', 'Invoice', help="This is the list of invoices that have been generated for this sale order. The same sale order may have been invoiced in several times (by line for example)."),
'picking_ids': fields.one2many('stock.picking', 'sale_id', 'Packing List', readonly=True, help="This is the list of picking list that have been generated for this invoice"),
'shipped':fields.boolean('Picked', readonly=True),
'invoiced':fields.boolean('Paid', readonly=True),
'invoiced': fields.function(_invoiced, method=True, string='Paid',
fnct_search=_invoiced_search, type='boolean'),
'note': fields.text('Notes'),
'amount_untaxed': fields.function(_amount_untaxed, method=True, string='Untaxed Amount'),
'amount_tax': fields.function(_amount_tax, method=True, string='Taxes'),
'amount_total': fields.function(_amount_total, method=True, string='Total'),
@ -187,7 +225,7 @@ class sale_order(osv.osv):
return False
cr.execute('select id from sale_order_line where order_id in ('+','.join(map(str, ids))+')', ('draft',))
line_ids = map(lambda x: x[0], cr.fetchall())
self.write(cr, uid, ids, {'state':'draft', 'invoice_ids':[], 'shipped':0, 'invoiced':0})
self.write(cr, uid, ids, {'state':'draft', 'invoice_ids':[], 'shipped':0})
self.pool.get('sale.order.line').write(cr, uid, line_ids, {'invoiced':False, 'state':'draft', 'invoice_lines':[(6,0,[])]})
wf_service = netsvc.LocalService("workflow")
for inv_id in ids:

View File

@ -77,8 +77,7 @@
<record model="workflow.activity" id="act_invoice_end">
<field name="wkf_id" ref="wkf_sale"/>
<field name="name">invoice_end</field>
<field name="kind">function</field>
<field name="action">write({'invoiced':1})</field>
<field name="kind">dummy</field>
</record>
<record model="workflow.activity" id="act_invoice_cancel">
<field name="wkf_id" ref="wkf_sale"/>