0

I want the client to be force to choose the journal in the invoice form view and not to have the first pre-selected.

Which is the correct way to remplace default, on the partner_id field change the the default journal choose event is tigger.

Edit

If I try to override the onchange_partner_id function I get the following error:

File "/opt/PycharmProjects/gca_odoo/clientes/client_PRINCE/models.py", line 22, in onchange_partner_id
    self.journal_id = False
  File "/opt/PycharmProjects/gca_odoo/3party/server/openerp/fields.py", line 847, in __set__
    record.ensure_one()
  File "/opt/PycharmProjects/gca_odoo/3party/server/openerp/models.py", line 5306, in ensure_one
    raise except_orm("ValueError", "Expected singleton: %s" % self)
except_orm: ('ValueError', 'Expected singleton: account.invoice()')

I use the following code:

class account_invoice(models.Model):
    _inherit = 'account.invoice'

    @api.multi
    def onchange_partner_id(self, type, partner_id, date_invoice=False,payment_term=False, partner_bank_id=False, company_id=False):
        ret = super(account_invoice,self).onchange_partner_id(type=type, partner_id= partner_id,
        date_invoice=date_invoice,payment_term=payment_term, partner_bank_id=partner_bank_id, company_id=company_id)
        self.journal_id = False
        return ret
ChesuCR
  • 9,352
  • 5
  • 51
  • 114
Mariano DAngelo
  • 920
  • 5
  • 18
  • 39

2 Answers2

0

You can override the onchange method, call is as super and after that, set the jopurnal field to False, in order to empty it.

EDIT: You are using the multi decorator. You should use one instead.

Alessandro Ruffolo
  • 1,575
  • 1
  • 16
  • 34
  • File "/opt/PycharmProjects/gca_odoo/clientes/client_PRINCE/models.py", line 22, in onchange_partner_id self.journal_id = False File "/opt/PycharmProjects/gca_odoo/3party/server/openerp/fields.py", line 847, in __set__ record.ensure_one() File "/opt/PycharmProjects/gca_odoo/3party/server/openerp/models.py", line 5306, in ensure_one raise except_orm("ValueError", "Expected singleton: %s" % self) – Mariano DAngelo Feb 29 '16 at 13:08
  • the code I use: @api.multi def onchange_partner_id(self, type, partner_id, date_invoice=False,payment_term=False, partner_bank_id=False, company_id=False): ret = super(account_invoice,self).onchange_partner_id(type=type, partner_id= partner_id, date_invoice=date_invoice,payment_term=payment_term, partner_bank_id=partner_bank_id, company_id=company_id) self.journal_id = False return ret – Mariano DAngelo Feb 29 '16 at 13:09
  • it is not possible to understand it in a comment. Edit the question with the code (formatted) – Alessandro Ruffolo Feb 29 '16 at 13:19
  • Not working, still the first journal is selected. thanks any way – Mariano DAngelo Feb 29 '16 at 14:08
0

I would do something like the following code, I am assuming you are overriding the right method:

@api.multi
def onchange_partner_id(self, type, partner_id, date_invoice=False, payment_term=False,
                        partner_bank_id=False, company_id=False):
    res = super(invoice, self).onchange_partner_id(
        type, partner_id, date_invoice,
        payment_term, partner_bank_id, company_id
    )
    if partner_id:
        res['value'].update({
            'journal_id': False,
        })
    return res
ChesuCR
  • 9,352
  • 5
  • 51
  • 114