[FIX] invoice created by delivery order

bzr revid: fp@tinyerp.com-20121218154855-hjwwfj3q3033oyn0
This commit is contained in:
Fabien Pinckaers 2012-12-18 16:48:55 +01:00
parent 891ea764fe
commit c131a7062e
4 changed files with 23 additions and 76 deletions

View File

@ -84,7 +84,7 @@ class procurement_order(osv.osv):
_inherit = ['mail.thread']
_log_create = False
_columns = {
'name': fields.char('Description', required=True),
'name': fields.text('Description', required=True),
'origin': fields.char('Source Document', size=64,
help="Reference of the document that created this Procurement.\n"
"This is automatically completed by OpenERP."),

View File

@ -19,7 +19,6 @@
<field name="procure_method"/>
<field name="state"/>
<field name="message"/>
<field name="name" invisible="1"/>
</tree>
</field>
</record>
@ -52,12 +51,18 @@
<field name="state" readonly="1" widget="statusbar" statusbar_visible="draft,confirmed" />
</header>
<sheet>
<label for="name" class="oe_edit_only"/>
<h1>
<field name="name" class="oe_inline"/>
<label string="-" attrs="{'invisible':[('origin','=',False)]}"/>
<field name="origin" class="oe_inline" placeholder="e.g. SO005"/>
<label for="product_id" class="oe_edit_only"/>
<field name="product_id" on_change="onchange_product_id(product_id)"/>
</h1>
<h2>
<label for="product_qty" class="oe_edit_only"/>
<div>
<field name="product_qty" class="oe_inline"/>
<field name="product_uom" class="oe_inline" groups="product.group_uom"/>
</div>
</h2>
<field name="name" placeholder="External note..."/>
<group>
<group>
<field name="date_planned"/>
@ -65,8 +70,9 @@
<field name="priority"/>
</group>
<group>
<field name="message"/>
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
<field name="origin" class="oe_inline" placeholder="e.g. SO005"/>
<field name="message"/>
</group>
</group>
<notebook>
@ -98,7 +104,7 @@
</group>
</page>
<page string="Notes">
<field name="note"/>
<field name="note" placeholder="Internal note..."/>
</page>
</notebook>
</sheet>

View File

@ -78,9 +78,8 @@ class procurement_order(osv.osv):
'remaining_hours': planned_hours,
'partner_id': procurement.sale_line_id and procurement.sale_line_id.order_id.partner_id.id or False,
'user_id': procurement.product_id.product_manager.id,
'notes': procurement.note,
'procurement_id': procurement.id,
'description': procurement.note,
'description': procurement.name + '\n' + (procurement.note or ''),
'project_id': project and project.id or False,
'company_id': procurement.company_id.id,
},context=context)

View File

@ -70,6 +70,14 @@ class stock_picking(osv.osv):
invoice_vals['fiscal_position'] = picking.sale_id.fiscal_position.id
invoice_vals['payment_term'] = picking.sale_id.payment_term.id
invoice_vals['user_id'] = picking.sale_id.user_id.id
invoice_vals['name'] = picking.sale_id.client_order_ref or ''
return invoice_vals
def _prepare_invoice_line(self, cr, uid, group, picking, move_line, invoice_id, invoice_vals, context=None):
invoice_vals = super(stock_picking, self)._prepare_invoice_line(cr, uid, group, picking, move_line, invoice_id, invoice_vals, context=context)
if picking.sale_id:
if move_line.sale_line_id:
invoice_vals['account_analytic_id'] = self._get_account_analytic_invoice(cr, uid, picking, move_line.sale_line_id.id)
return invoice_vals
def _get_price_unit_invoice(self, cursor, user, move_line, type):
@ -112,72 +120,6 @@ class stock_picking(osv.osv):
})
return super(stock_picking, self)._invoice_hook(cursor, user, picking, invoice_id)
def action_invoice_create(self, cursor, user, ids, journal_id=False,
group=False, type='out_invoice', context=None):
if context is None:
context = {}
invoice_obj = self.pool.get('account.invoice')
picking_obj = self.pool.get('stock.picking')
invoice_line_obj = self.pool.get('account.invoice.line')
fiscal_position_obj = self.pool.get('account.fiscal.position')
order_line_obj = self.pool.get('sale.order.line')
result = super(stock_picking, self).action_invoice_create(cursor, user,
ids, journal_id=journal_id, group=group, type=type,
context=context)
picking_ids = result.keys()
invoice_ids = result.values()
invoices = {}
for invoice in invoice_obj.browse(cursor, user, invoice_ids,
context=context):
invoices[invoice.id] = invoice
for picking in picking_obj.browse(cursor, user, picking_ids,
context=context):
if not picking.sale_id or picking.backorder_id:
continue
sale_lines = picking.sale_id.order_line
invoice_created = invoices[result[picking.id]]
if picking.sale_id.user_id:
invoice_obj.write(cursor, user, [invoice_created.id], {'user_id': picking.sale_id.user_id.id}, context=context)
if picking.sale_id.fiscal_position:
invoice_obj.write(cursor, user, [invoice_created.id], {'fiscal_position': picking.sale_id.fiscal_position.id}, context=context)
if picking.sale_id.client_order_ref:
inv_name = picking.sale_id.client_order_ref + " : " + invoice_created.name
invoice_obj.write(cursor, user, [invoice_created.id], {'name': inv_name}, context=context)
for sale_line in sale_lines:
account_id = False
if not type:
type = context.get('inv_type', False)
if group:
name = picking.name + '-' + sale_line.name
else:
name = sale_line.name
if sale_line.product_id.type == 'service' and sale_line.invoiced == False:
if type in ('out_invoice', 'out_refund'):
account_id = sale_line.product_id.product_tmpl_id.\
property_account_income.id
if not account_id:
account_id = sale_line.product_id.categ_id.\
property_account_income_categ.id
else:
account_id = sale_line.product_id.product_tmpl_id.\
property_account_expense.id
if not account_id:
account_id = sale_line.product_id.categ_id.\
property_account_expense_categ.id
vals = order_line_obj._prepare_order_line_invoice_line(cursor, user, sale_line, account_id, context)
if vals: #note: in some cases we may not want to include all service lines as invoice lines
vals['name'] = name
vals['account_analytic_id'] = self._get_account_analytic_invoice(cursor, user, picking, sale_line)
vals['invoice_id'] = invoices[result[picking.id]].id
invoice_line_id = invoice_line_obj.create(cursor, user, vals, context=context)
sale_line.write({'invoice_lines': [(4, invoice_line_id)]})
invoice_obj.button_compute(cursor, user, [invoice_created.id], context=context)
return result
# Redefinition of the new field in order to update the model stock.picking.out in the orm
# FIXME: this is a temporary workaround because of a framework bug (ref: lp996816). It should be removed as soon as
# the bug is fixed