Merge invoice and credit note
issue5225 review18921002
This commit is contained in:
1 parent
ba2faab793
commit
f78c981f45
4 files changed
+11
-19
No files matched your search
+3
-9
@@ -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'
|
||||
|
||||
+2
-4
@@ -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,
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user