Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
5583 Visualizzazioni

I created a sequence via user interface : Configuration/Technical/Sequences and identifiers/ Sequences

I also created its code so as so to call it, on the python method on : Configuration/technical/Sequence Code

The model concerned is account.invoice , I want that when validating the invoice, it switches to state open, and generate a sequence  number, for that : 

1.  I overrided the type of validate invoice button to object ( it was workflow )

2.  I used invoice_validate as a button method , and overrided it.

3.  I overrided the number field, it was related, I made it simple char field.

and then I used the sequence, after the code for more explaination.

.py :  

class AccountInvoice(orm.Model):

    _inherit = 'account.invoice'
    _name = 'account.invoice'
    _colmuns = {
        'number': fields.char(size=64, readonly=True),
    }

    def invoice_validate(self, cr, uid, ids, context=None):

        num_facture = self.pool.get('ir.sequence').get(cr, uid,'Invoice_number')

        self.write(cr, uid, ids[0], {'state':'open','number': num_facture,}, context=context)
        return True

.xml :

        <record id="invoice_form_custom" model="ir.ui.view">
            <field name="name">invoice.form.custom</field>
            <field name="model">account.invoice</field>
            <field name="inherit_id" ref="account.invoice_form"/>
            <field name="arch" type="xml">
                <xpath expr="//form/header/button[@name='invoice_open']" position="replace">
                    <button name="invoice_validate" states="draft" string="Valider" type="object" class="oe_highlight"/>
                </xpath>
            </field>
        </record>

The issue is that the sequence is not displayed on the field "number" I overrided, should I add "number" on the xml view also ?

Thanks

 

Avatar
Abbandona
Risposta migliore

Hi, the invoice number is associated with Journal Entry Number (account.move), so you cannot modify like that...

And Invoice validate action is performed by a Workflow..

So do this, write your own function/method say action_XXX(), in which you generate and update the Number

Then override the workflow function to include your custom method...

Like this...


        <record id="act_open" model="workflow.activity">
            <field name="wkf_id" ref="wkf"/>
            <field name="name">open</field>
            <field name="action">action_date_assign()
action_XXX()
action_move_create()
action_number()
invoice_validate()</field>
            <field name="kind">function</field>
        </record>

Avatar
Abbandona
Autore

Hi, I don't want to keep the actual invoice validation workflow, so no need to override it, I changed the type of the button "validate" into object, and related it to a method "x()", which is doing the right treatment I want. I want to give my validated invoice his own sequence, because it's no longer related to account_move. My problem now, is that I want to create a field, taking the new sequence and replacing the old invoice number field.it doesn't work with inheritance, always XML architecture error rising. The sequence is generated, and displayed on any char field of the form, but I want to place it in the heading of the invoice form right after INVOICE ( in bold caracter style).

Risposta migliore

To get a field displayed, you must add it to a view (in .xml file)

Avatar
Abbandona
Autore

I've added it, here is the xml file : invoice.form.custom account.invoice <xpath expr="//form/header/button[@name='invoice_open']" position="replace"> <xpath expr="//form/sheet/group/group/field[@name='partner_id']" position="before"> XML architecture error rising.

We are talking about the field "number" !!!

Autore

Oh sorry, I pasted the wrong code, I added number with inheritance in the XML file, it didn't work, The purpose is to change the field number, so as to get a new sequence.

Post correlati Risposte Visualizzazioni Attività
0
set 24
1420
2
mar 24
3086
2
feb 23
3656
6
ott 20
37785
1
set 20
4362