Hi guys,
I'm extending the sale and account module and added my custom fields in a custom module. I've added fields in both the sale.order.line model and the account.invoice.line model:
class custom_sale_order_line_fields(models.Model): _inherit = 'sale.order.line' hoogte = fields.Integer() breedte = fields.Integer() aantal = fields.Integer() #Checkboxes links = fields.Boolean() rechts = fields.Boolean() boven = fields.Boolean() onder = fields.Boolean() kleur = fields.Selection((('w','Wit'), ('z','Zwart'), ('g','Groen'),('r','Rood'))) class aa_invoice_custom_lines(models.Model): _inherit = 'account.invoice.line' hoogte = fields.Integer() breedte = fields.Integer() aantal = fields.Integer() #Checkboxes links = fields.Boolean() rechts = fields.Boolean() boven = fields.Boolean() onder = fields.Boolean() kleur = fields.Selection((('w','wit'), ('z','zwart'), ('g','groen'),('r','rood')))
The fields are added in both the view for a new sale order and the view for an invoice:
<openerp> <data> <record id="sale.view_order_form_inherit" model="ir.ui.view"> <field name="name">sale.order.form.inherit</field> <field name="model">sale.order</field> <field name="inherit_id" ref="sale.view_order_form"/> <field name="arch" type="xml"> <xpath expr="//tree[@string='Sales Order Lines']/field[@name='name']" position="after"> <field name="links"/> <field name="rechts"/> <field name="boven"/> <field name="onder"/> <field name="kleur"/> <field name="hoogte" on_change="on_change_hoeveelheid_berekenen(hoogte,breedte,aantal)"/> <field name="breedte" on_change="on_change_hoeveelheid_berekenen(hoogte,breedte,aantal)"/> <field name="aantal" on_change="on_change_hoeveelheid_berekenen(hoogte,breedte,aantal)"/> </xpath> </field> </record> <record id="account.invoice_form_inherit3" model="ir.ui.view"> <field name="name">account.invoice.form.inherit3</field> <field name="model">account.invoice</field> <field name="inherit_id" ref="account.invoice_form"/> <field name="arch" type="xml"> <xpath expr="//tree[@string='Invoice Lines']/field[@name='name']" position="after"> <field name="links"/> <field name="rechts"/> <field name="boven"/> <field name="onder"/> <field name="kleur"/> <field name="hoogte" on_change="on_change_hoeveelheid_factuur_berekenen(hoogte,breedte,aantal)"/> <field name="breedte" on_change="on_change_hoeveelheid_factuur_berekenen(hoogte,breedte,aantal)"/> <field name="aantal" on_change="on_change_hoeveelheid_factuur_berekenen(hoogte,breedte,aantal)"/> </xpath> </field> </record> </data> </openerp>
The next thing that I need is that when the user opens up a sales order and clicks on the button 'Create Invoice' that the filled in data from the sales order gets passed on to the invoice that is automatically generated.
The button 'Create Invoice' seems to come from /sale/wizard/sale_line_invoice.xml from this record:
<record id="action_view_sale_order_line_make_invoice" model="ir.actions.act_window"> <field name="name">Create Invoice</field> <field name="type">ir.actions.act_window</field> <field name="res_model">sale.order.line.make.invoice</field> <field name="view_type">form</field> <field name="view_mode">form</field> <field name="view_id" ref="view_sale_order_line_make_invoice"/> <field name="target">new</field> </record>
What I don't understand now is where I should add the logic to transfer data from my custom fields from a sales order to an invoice. How do I know which code this action triggers and how should I transfer the data from the sale order to the invoice? It looks like the data is transferred in the method make_invoice (addons/sale/wizard/sale_line_invoice.py in the following lines:
#TODO: merge with sale.py/make_invoice def make_invoice(order, lines): """ To make invoices. @param order: @param lines: @return: """ a = order.partner_id.property_account_receivable.id if order.partner_id and order.partner_id.property_payment_term.id: pay_term = order.partner_id.property_payment_term.id else: pay_term = False inv = { 'name': order.client_order_ref or '', 'origin': order.name, 'type': 'out_invoice', 'reference': "P%dSO%d" % (order.partner_id.id, order.id), 'account_id': a, 'partner_id': order.partner_invoice_id.id, 'invoice_line': [(6, 0, lines)], 'currency_id' : order.pricelist_id.currency_id.id, 'comment': order.note, 'payment_term': pay_term, 'fiscal_position': order.fiscal_position.id or order.partner_id.property_account_position.id, 'user_id': order.user_id and order.user_id.id or False, 'company_id': order.company_id and order.company_id.id or False, 'date_invoice': fields.date.today(), } inv_id = self.pool.get('account.invoice').create(cr, uid, inv) return inv_idBut how can I add my custom fields to be added on the invoice lines too?
Thanks,
Yenthe