Odoo Help

0

1
2 Answers
1
kaynis
23/10/13, 08:45

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>
13 Comments
babis peroukas
23/10/13, 08:56

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?

babis peroukas
23/10/13, 09:03

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

kaynis
23/10/13, 10:47

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

kaynis
23/10/13, 10:56

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.

babis peroukas
23/10/13, 10:58

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

babis peroukas
23/10/13, 11:09

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

kaynis
23/10/13, 11:12

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

babis peroukas
23/10/13, 11:16

Thanks a lot :)

kaynis
23/10/13, 11:25

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

babis peroukas
25/10/13, 07:28

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!

babis peroukas
25/10/13, 07:29

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>

babis peroukas
25/10/13, 07:30

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

wrote 2 comments cause i cant post it in one

babis peroukas
25/10/13, 09:24

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

0
babis peroukas
23/10/13, 09:22

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 :)

1 Comment
Pau Ubach
16/09/14, 05:01

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

Ask a Question
Keep Informed
2 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our eLearning platform and experience all Odoo Apps through learning videos, use cases and quizzes.

Test it now