Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
13343 Weergaven

Hello,

I use the developer mode in openerp 7 so i can create some fields that are needed. I 've created a char field in the sale order form (x_duty). Is there any way to create another field in the account.invoice.form so it automaticly gets the value of the x_duty field from the sales order form?

Thank you in advance

Avatar
Annuleer

First add the field you want to the invoice the same way you did the partner and create an onchange function on the customer name in the invoice.

Auteur

hi and thanks for the answer but... what u mean with "the same way"? are there any parameters i gotta add?

You have to create an onchange function based on another field, e.g, the partner name or the sales order id

Auteur

can u please explain me? in which file do i have to create that function and how? Also, does it matters what type of field it is? I mean can I send the value of a char field in sales.order form to a field in invoice form? Thanks for the answers :)

Beste antwoord

Use something of this nature which I copied form one of the modules

class sale_order(osv.osv):
_inherit = 'sale.order'
def _make_invoice(self, cr, uid, order, lines, context=None):
    inv_id = super(sale_order, self)._make_invoice(cr, uid, order, lines, context)
    inv_obj = self.pool.get('account.invoice')
    if order.name_of_your_field:
        inv_obj.write(cr, uid, [inv_id], {'name_of_your_field': name_of_your_field.id}, context=context)
    return inv_id

sale_order()

class account_invoice(osv.osv):    
_inherit = "account.invoice"
_columns = {
    'name_of_your_field': fields.many2one(your field characteristics),
}
 account_invoice()

this is used to take the delivery address in sales order to the invoice. This should help you. Add the code below in your xml view

   <?xml version="1.0" encoding="UTF-8"?>
   <openerp>
 <data>
    <record model="ir.ui.view" id="invoice_form_shipping_address">
        <field name="name">account.invoice.form.shipping.address</field>
        <field name="model">account.invoice</field>
        <field name="inherit_id" ref="account.invoice_form"/>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <field name="address_invoice_id" position="after">
                <field colspan="4" name="name_of_your_field" groups="base.group_extended"/>
            </field>
        </field>
    </record>
</data>
</openerp>
Avatar
Annuleer
Auteur

that's the one I can understand. My problem is that I dont know in which file and where in the file I have to put this. I mean it's in the sales.py (obviously) but do I have to change the _make_invoice function?

Auteur

Ah, forgot to mention, I 've not made a custom module (I dont know how), so all I m trying to do is to modify the existing sales.py

You have to create your own module for this. Never change the core module unless you are absolutely totally sure what you are doing.

Create a new module call it xname_to_invoice, i.e create a new folder inside the addon folder and give it that name. Then create you __init__.py and inside the __init__.py write "import sales" then save this. Create a __openerp.py too and add the dependent modules too see examples online. then create sales.py and inside add your code similar to the example I gave above.

Auteur

Ok, I dont know how it workds though. If i override _make_invoice function how can it take place in sale.order?

Auteur

I ll give it a try and I ll inform ou. thank you very much

I have made some changes that can point you in the direction you want.

Auteur

Thanks a lot :)

if you are still having problems let me know. I am a little busy but will try and help.

Auteur

helo again :) i did this and now, when i m goin to install it it says: error while validating arch fields: Invalid XML for View Architecture!

Auteur

my xml is this:

<?xml version="1.0" encoding="UTF-8"?> <openerp> <data> <record model="ir.ui.view" id="invoice_form_shipping_address"> <field name="name">account.invoice.form.shipping.address</field> <field name="model">account.invoice</field> <field name="inherit_id" ref="account.invoice_form"/> <field name="type">form</field> <field name="arch" type="xml"> <field name="address_invoice_id" position="after"> <field colspan="4" name="x_custom_field" groups="base.group_extended"/> </field> </field>

Auteur

</field> </record> </data> </openerp>

wrote 2 comments cause i cant post it in one

Auteur

i replaced account.invoice_form with account.invoice.form and then it says: ValueError: too many values to unpack

Auteur Beste antwoord

Hi and thanks for all help :) I ' solved it by edtiting the sale.py in sale module. I just had to edit _prepare_invoice function and add my custom fields to its invoice_vals like this:

    invoice_vals = {
        'name': order.client_order_ref or '',
        'origin': order.name,
        'type': 'out_invoice',
        'reference': order.client_order_ref or order.name,
        'account_id': order.partner_id.property_account_receivable.id,
        'partner_id': order.partner_invoice_id.id,
        'journal_id': journal_ids[0],
        'invoice_line': [(6, 0, lines)],
        'currency_id': order.pricelist_id.currency_id.id,
        'comment': order.note,
        'payment_term': order.payment_term and order.payment_term.id or False,
        'fiscal_position': order.fiscal_position.id or order.partner_id.property_account_position.id,
        'date_invoice': context.get('date_invoice', False),
        'company_id': order.company_id.id,
        'user_id': order.user_id and order.user_id.id or False,
        'x_destplace': order.x_destplace,
        'x_loadplace': order.x_loadplace,
        'x_vehivle': order.x_vehicle
    }

Then I created those fileds in both models and my problem solved :)

Avatar
Annuleer

Someone told you already but I repeat: Never ever change the core modules.

Gerelateerde posts Antwoorden Weergaven Activiteit
2
mrt. 15
6976
3
jun. 20
9747
2
mrt. 15
6603
3
jun. 25
896
3
feb. 25
6827