diff --git a/commission.py b/commission.py index 46f489cdc2..0a808a1def 100644 --- a/commission.py +++ b/commission.py @@ -335,10 +335,7 @@ class Commission(ModelSQL, ModelView): 'in': 'out', 'out': 'in', }.get(self.type_) - document = 'invoice' if self.amount > 0 else 'credit_note' - return (('agent', self.agent), - ('type', '%s_%s' % (direction, document)), - ) + return (('agent', self.agent), ('type', direction)) @classmethod def get_journal(cls): @@ -357,7 +354,7 @@ class Commission(ModelSQL, ModelView): Invoice = pool.get('account.invoice') agent = key['agent'] - if key['type'].startswith('out'): + if key['type'] == 'out': payment_term = agent.party.customer_payment_term else: payment_term = agent.party.supplier_payment_term @@ -381,7 +378,7 @@ class Commission(ModelSQL, ModelView): InvoiceLine = pool.get('account.invoice.line') def sign(commission): - if invoice.type.startswith(commission.type_): + if invoice.type == commission.type_: return -1 else: return 1 @@ -390,9 +387,6 @@ class Commission(ModelSQL, ModelView): amount = invoice.currency.round( sum(c.amount * sign(c) for c in commissions)) - if invoice.type.endswith('credit_note'): - amount *= -1 - invoice_line = InvoiceLine() invoice_line.invoice = invoice invoice_line.type = 'line' diff --git a/invoice.py b/invoice.py index 1e50e2fce3..cfad166cb8 100644 --- a/invoice.py +++ b/invoice.py @@ -115,10 +115,8 @@ class InvoiceLine: ], states={ 'invisible': If(Bool(Eval('_parent_invoice')), - Eval('_parent_invoice', {}).get('type').in_( - ['in_invoice', 'in_credit_note']), - Eval('invoice_type').in_( - ['in_invoice', 'in_credit_note'])), + Eval('_parent_invoice', {}).get('type') == 'in', + Eval('invoice_type') == 'in'), }, depends=['invoice_type', 'company']) commissions = fields.One2Many('commission', 'origin', 'Commissions', readonly=True, diff --git a/sale.py b/sale.py index 36a7ddbabc..162c464428 100644 --- a/sale.py +++ b/sale.py @@ -22,8 +22,8 @@ class Sale: }, depends=['state', 'company']) - def create_invoice(self, invoice_type): - invoice = super(Sale, self).create_invoice(invoice_type) + def create_invoice(self): + invoice = super(Sale, self).create_invoice() if invoice: invoice.agent = self.agent invoice.save() @@ -39,8 +39,8 @@ class SaleLine: ('company', '=', Eval('_parent_sale', {}).get('company', -1)), ]) - def get_invoice_line(self, invoice_type): - lines = super(SaleLine, self).get_invoice_line(invoice_type) + def get_invoice_line(self): + lines = super(SaleLine, self).get_invoice_line() if self.principal: for line in lines: if line.product == self.product: diff --git a/tests/scenario_commission.rst b/tests/scenario_commission.rst index 1f9470f937..65c7a4e9b5 100644 --- a/tests/scenario_commission.rst +++ b/tests/scenario_commission.rst @@ -175,7 +175,7 @@ Create commission invoices:: >>> create_invoice.execute('create_') >>> invoice, = Invoice.find([ - ... ('type', '=', 'in_invoice'), + ... ('type', '=', 'in'), ... ]) >>> invoice.total_amount Decimal('10.00') @@ -186,7 +186,7 @@ Create commission invoices:: True >>> invoice, = Invoice.find([ - ... ('type', '=', 'out_invoice'), + ... ('type', '=', 'out'), ... ('party', '=', principal.party.id), ... ]) >>> invoice.total_amount