Skip to content

Commit

Permalink
Included tests for Partial Payments.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbcosta committed Oct 28, 2016
1 parent d2a1045 commit fd156c0
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 0 deletions.
22 changes: 22 additions & 0 deletions sale_commission/test/sale_commission_demo.yml
Expand Up @@ -78,6 +78,28 @@
assert sale_order.invoice_ids, "Invoice should be created."
assert sale_order.invoice_exists, "Order is not invoiced."
assert sale_order.invoiced, "Order is not paid."
-
I try to create the Settlement after paid Invoice
-
!python {model: sale.commission.make.settle}: |
import datetime
import dateutil.relativedelta
now = datetime.datetime.now()
wizard_id = self.create(
cr, uid, {'date_to': now + dateutil.relativedelta.relativedelta(months=1)})
result = self.action_settle(cr, uid, [wizard_id], context=None)
-
I open the Settlements to check if was create.
-
!python {model: sale.commission.settlement}: |
settlement_ids = self.search(cr, uid, [('state', '=', 'settled')])
assert settlement_ids, "After Invoice are Paid need to be possible create Settlements."
-
I check the Line Agent is settled now
-
!python {model: account.invoice.line.agent}: |
account_invoice_line_agent_ids = self.search(cr, uid, [('settled', '=', 't')])
assert account_invoice_line_agent_ids, "The Invoice Line Agent need to be settled."
-
I create another Sale Order with a Agent who has the Type of Commission - Invoice Based
-
Expand Down
123 changes: 123 additions & 0 deletions sale_commission/tests/test_sale_commission.py
Expand Up @@ -70,6 +70,7 @@ def setUp(self):
self.settle_model = self.env['sale.commission.settlement']
self.make_settle_model = self.env['sale.commission.make.settle']
self.make_inv_model = self.env['sale.commission.make.invoice']
self.account_voucher = self.env['account.voucher']
self.saleorder1 = self.sale_order_model.create({
'partner_id': self.partner.id,
'order_line': [(0, 0, {
Expand Down Expand Up @@ -145,6 +146,26 @@ def setUp(self):
})]
})

self.saleorder7 = self.sale_order_model.create({
'partner_id': self.ref('base.res_partner_2'),
'date_order':
datetime.datetime.now() -
dateutil.relativedelta.relativedelta(months=1, days=7),
'payment_term': self.ref(
'sale_commission.demo_payment_term_07_28'),
'order_line': [(0, 0, {
'product_id': self.ref('product.product_product_21'),
'product_uom_qty': 10.0,
'product_uom': self.ref('product.product_uom_unit'),
'agents': [(0, 0, {
'agent': self.ref(
'sale_commission.partial_payments_sale_agent'),
'commission': self.ref(
'sale_commission.demo_commission_partial_payments'),
})]
})]
})

def test_sale_commission_gross_amount_payment(self):
self.saleorder1.signal_workflow('order_confirm')
payment = self.advance_inv_model.create({
Expand Down Expand Up @@ -386,3 +407,105 @@ def test_wrong_section(self):
'percent': 20.0,
})]
})

def test_sale_commission_gross_amount_partial_payments(self):
self.saleorder7.signal_workflow('order_confirm')
payment = self.advance_inv_model.create({
'advance_payment_method': 'all'
})
payment.with_context(active_model='sale.order',
active_ids=[self.saleorder7.id],
active_id=self.saleorder7.id).create_invoices()
self.assertNotEquals(
len(self.saleorder7.invoice_ids), 0,
"Invoice should be created after make advance invoice where type"
" is 'Invoice all the Sale Order'.")
for invoice in self.saleorder7.invoice_ids:
invoice.date_invoice = fields.Date.today()
invoice.signal_workflow('invoice_open')
wizard = self.make_settle_model.create(
{'date_to': (datetime.datetime.now() +
dateutil.relativedelta.relativedelta(months=1))})
wizard.action_settle()
settlements = self.settle_model.search([('state', '=', 'settled')])
self.assertEquals(
len(settlements), 0,
"The Type of Commission only allows create the Settlements when"
" the Partial Payments of Invoices are Paid.")
journals = self.env['account.journal'].search([
('type', '=', 'cash'),
('company_id', '=', self.saleorder1.company_id.id)
], limit=1)
for invoice in self.saleorder7.invoice_ids:
move_line_07 = self.env['account.move.line'].search(
['&', ('move_id', '=', invoice.move_id.id),
('date_maturity', '=', invoice.date_due)])
account_voucher_07 = self.account_voucher.create({
'partner_id': self.saleorder7.partner_id.id,
'amount': invoice.amount_total / 2,
'journal_id': journals[:1].id,
'date': invoice.date_due,
'company_id': invoice.company_id.id,
'account_id': 9,
'line_cr_ids': [
[0, 0, {
'date_due': invoice.date_due,
'reconcile': True,
'date_original': invoice.date_due,
'move_line_id': move_line_07.id,
'amount_unreconciled': 10000,
'amount': 10000,
'amount_original': 10000,
'account_id': 9,
}]]

})
account_voucher_07.button_proforma_voucher()

wizard = self.make_settle_model.create(
{'date_to': (datetime.datetime.now() +
dateutil.relativedelta.relativedelta(months=1))})
wizard.action_settle()
settlements = self.settle_model.search([('id', '!=', None)])
if settlements:
for settlement in settlements:
self.assertEquals(
(self.saleorder7.commission_total / 2), settlement.total,
"The Type of Commission only allows create the Settlements"
" to proportional of Partial Payments.")

move_line_28 = self.env['account.move.line'].search(
['&', ('move_id', '=', invoice.move_id.id),
('date_maturity', '!=', invoice.date_due)])
account_voucher_28 = self.account_voucher.create({
'partner_id': self.saleorder7.partner_id.id,
'amount': invoice.amount_total / 2,
'journal_id': journals[:1].id,
'date': move_line_28.date_maturity,
'company_id': invoice.company_id.id,
'account_id': 9,
'line_cr_ids': [
[0, 0, {
'date_due': move_line_28.date_maturity,
'reconcile': True,
'date_original': '2016-09-01',
'move_line_id': move_line_28.id,
'amount_unreconciled': 10000,
'amount': 10000,
'amount_original': 10000,
'account_id': 9,
}]]

})
account_voucher_28.button_proforma_voucher()
wizard = self.make_settle_model.create(
{'date_to': (datetime.datetime.now() +
dateutil.relativedelta.relativedelta(months=1))})
wizard.action_settle()
settlements = self.settle_model.search([('id', '!=', None)])
if settlements:
for settlement in settlements:
self.assertEquals(
(self.saleorder7.commission_total / 2), settlement.total,
"The Type of Commission only allows create the Settlements"
" to proportional of Partial Payments.")

0 comments on commit fd156c0

Please sign in to comment.