In model account_invoice.py I have the following doc type:
TYPE2REFUND = {
'out_invoice': 'out_refund', # Customer Invoice
'in_invoice': 'in_refund', # Vendor Bill
'out_refund': 'out_invoice', # Customer Refund
'in_refund': 'in_invoice', # Vendor Refund
}
What I need to know is how to "assign the actual invoice type" to a variable in order
to evaluate it in an if, something like this:
if type in ('out_invoice', 'out_refund'):
#here assign the document type to a variable.
The problem is that I can't get the invoice type in the variable.
This is my code:class einvoice_base_document(models.Model):
_inherit = "account.invoice"
doc_type = fields.Char("Tipo de documento", compute='get_doc_type')@api.multi
def _get_doc_type(self):
self.doc_type = self._context('type')
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
Context have {'default_type':'out_invoice', 'type':'out_invoice'} in case of Customer Invoice so you can get self._context('default_type') or self._context('type').
Context have {'default_type':'in_invoice', 'type':'in_invoice'} in case of Vendor Bill so you can get self._context('default_type') or self._context('type')
How about using the TYPE field on the Invoice (there is already a field called TYPE which has the Invoice type assigned to it)?
This field already exists and is how Odoo lets users see the Invoice Type.
type = fields.Selection([
('out_invoice','Customer Invoice'),
('in_invoice','Vendor Bill'),
('out_refund','Customer Credit Note'),
('in_refund','Vendor Credit Note'),
], readonly=True, index=True, change_default=True,
default=lambda self: self._context.get('type', 'out_invoice'),
track_visibility='always')
For example, the Customer Invoices Window Action has this domain:
[('type','=','out_invoice')]
For odoo11 use self._context.get('type')
Thanks Ray, I already resolved this using: self._context('type')