mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
Code review
This commit is contained in:
@@ -153,7 +153,9 @@ class AccountSpread(models.Model):
|
||||
'invoice_line_ids': [(6, 0, [invoice_line.id])],
|
||||
})
|
||||
|
||||
@api.multi
|
||||
@api.depends(
|
||||
'estimated_amount', 'invoice_line_id.price_subtotal',
|
||||
'line_ids.move_id.amount', 'line_ids.move_id.state')
|
||||
def _compute_amounts(self):
|
||||
for spread in self:
|
||||
moves_amount = 0.0
|
||||
|
||||
@@ -75,7 +75,7 @@ class TestAccountInvoiceSpread(AccountingTestCase):
|
||||
})
|
||||
|
||||
self.invoice_2 = self.env['account.invoice'].with_context(
|
||||
default_type='in_invoice'
|
||||
default_type='out_invoice'
|
||||
).create({
|
||||
'partner_id': partner.id,
|
||||
'account_id': self.invoice_account.id,
|
||||
@@ -168,15 +168,19 @@ class TestAccountInvoiceSpread(AccountingTestCase):
|
||||
self.assertFalse(wizard1.spread_id)
|
||||
self.assertEqual(wizard1.company_id, my_company)
|
||||
self.assertEqual(wizard1.spread_action_type, 'link')
|
||||
self.assertTrue(wizard1.spread_account_id)
|
||||
self.assertTrue(wizard1.spread_journal_id)
|
||||
self.assertEqual(wizard1.spread_account_id, account_payable)
|
||||
self.assertEqual(wizard1.spread_journal_id.id, exp_journal)
|
||||
self.assertFalse(wizard1.spread_account_id)
|
||||
self.assertFalse(wizard1.spread_journal_id)
|
||||
|
||||
res_onchange = wizard1.onchange_invoice_type()
|
||||
self.assertTrue(res_onchange)
|
||||
self.assertTrue(res_onchange.get('domain'))
|
||||
|
||||
wizard1._onchange_spread_journal_account()
|
||||
self.assertTrue(wizard1.spread_account_id)
|
||||
self.assertTrue(wizard1.spread_journal_id)
|
||||
self.assertEqual(wizard1.spread_account_id, account_payable)
|
||||
self.assertEqual(wizard1.spread_journal_id.id, exp_journal)
|
||||
|
||||
wizard2 = Wizard.with_context(
|
||||
default_invoice_line_id=self.invoice_line_2.id,
|
||||
default_company_id=my_company.id,
|
||||
@@ -188,15 +192,19 @@ class TestAccountInvoiceSpread(AccountingTestCase):
|
||||
self.assertFalse(wizard2.spread_id)
|
||||
self.assertEqual(wizard2.company_id, my_company)
|
||||
self.assertEqual(wizard2.spread_action_type, 'link')
|
||||
self.assertTrue(wizard2.spread_account_id)
|
||||
self.assertTrue(wizard2.spread_journal_id)
|
||||
self.assertEqual(wizard2.spread_account_id, account_revenue)
|
||||
self.assertEqual(wizard2.spread_journal_id.id, sales_journal)
|
||||
self.assertFalse(wizard2.spread_account_id)
|
||||
self.assertFalse(wizard2.spread_journal_id)
|
||||
|
||||
res_onchange = wizard2.onchange_invoice_type()
|
||||
self.assertTrue(res_onchange)
|
||||
self.assertTrue(res_onchange.get('domain'))
|
||||
|
||||
wizard2._onchange_spread_journal_account()
|
||||
self.assertTrue(wizard2.spread_account_id)
|
||||
self.assertTrue(wizard2.spread_journal_id)
|
||||
self.assertEqual(wizard2.spread_account_id, account_revenue)
|
||||
self.assertEqual(wizard2.spread_journal_id.id, sales_journal)
|
||||
|
||||
def test_03_link_invoice_line_with_spread_sheet(self):
|
||||
|
||||
my_company = self.env.user.company_id
|
||||
@@ -265,10 +273,13 @@ class TestAccountInvoiceSpread(AccountingTestCase):
|
||||
default_company_id=my_company.id,
|
||||
).create({
|
||||
'spread_action_type': 'new',
|
||||
})
|
||||
self.assertEqual(wizard1.spread_action_type, 'new')
|
||||
|
||||
wizard1.write({
|
||||
'spread_account_id': spread_account.id,
|
||||
'spread_journal_id': spread_journal_id,
|
||||
})
|
||||
self.assertEqual(wizard1.spread_action_type, 'new')
|
||||
|
||||
res_action = wizard1.confirm()
|
||||
self.assertTrue(isinstance(res_action, dict))
|
||||
@@ -296,10 +307,13 @@ class TestAccountInvoiceSpread(AccountingTestCase):
|
||||
default_company_id=my_company.id,
|
||||
).create({
|
||||
'spread_action_type': 'new',
|
||||
})
|
||||
self.assertEqual(wizard2.spread_action_type, 'new')
|
||||
|
||||
wizard2.write({
|
||||
'spread_account_id': spread_account.id,
|
||||
'spread_journal_id': spread_journal_id,
|
||||
})
|
||||
self.assertEqual(wizard2.spread_action_type, 'new')
|
||||
|
||||
res_action = wizard2.confirm()
|
||||
self.assertTrue(isinstance(res_action, dict))
|
||||
@@ -370,10 +384,13 @@ class TestAccountInvoiceSpread(AccountingTestCase):
|
||||
default_company_id=my_company.id,
|
||||
).create({
|
||||
'spread_action_type': 'new',
|
||||
})
|
||||
self.assertEqual(wizard2.spread_action_type, 'new')
|
||||
|
||||
wizard2.write({
|
||||
'spread_account_id': spread_account.id,
|
||||
'spread_journal_id': spread_journal_id,
|
||||
})
|
||||
self.assertEqual(wizard2.spread_action_type, 'new')
|
||||
|
||||
res_action = wizard2.confirm()
|
||||
self.assertTrue(isinstance(res_action, dict))
|
||||
|
||||
@@ -148,8 +148,8 @@ class TestComputeSpreadBoard(AccountingTestCase):
|
||||
self.assertEqual(self.spread.unspread_amount, 1000.0)
|
||||
self.assertEqual(self.spread.unposted_amount, 1000.0)
|
||||
|
||||
spread_lines.create_and_reconcile_moves()
|
||||
for line in spread_lines:
|
||||
self.spread.line_ids.create_and_reconcile_moves()
|
||||
for line in self.spread.line_ids:
|
||||
self.assertTrue(line.move_id)
|
||||
|
||||
def test_03_supplier_invoice(self):
|
||||
@@ -190,6 +190,7 @@ class TestComputeSpreadBoard(AccountingTestCase):
|
||||
self.assertEqual('2017-10-31', spread_lines[9].date)
|
||||
self.assertEqual('2017-11-30', spread_lines[10].date)
|
||||
self.assertEqual('2017-12-31', spread_lines[11].date)
|
||||
self.assertEqual('2018-01-31', spread_lines[12].date)
|
||||
|
||||
for line in spread_lines:
|
||||
self.assertFalse(line.move_id)
|
||||
@@ -203,6 +204,7 @@ class TestComputeSpreadBoard(AccountingTestCase):
|
||||
self.assertTrue(any(line.move_id for line in spread_lines))
|
||||
self.assertTrue(any(not line.move_id for line in spread_lines))
|
||||
|
||||
self.spread._compute_amounts()
|
||||
self.assertEqual(self.spread.unspread_amount, 830.65)
|
||||
self.assertEqual(self.spread.unposted_amount, 1000.0)
|
||||
|
||||
@@ -235,6 +237,7 @@ class TestComputeSpreadBoard(AccountingTestCase):
|
||||
self.assertEqual('2017-10-31', spread_lines[9].date)
|
||||
self.assertEqual('2017-11-30', spread_lines[10].date)
|
||||
self.assertEqual('2017-12-31', spread_lines[11].date)
|
||||
self.assertEqual('2018-01-31', spread_lines[12].date)
|
||||
|
||||
def test_04_supplier_invoice(self):
|
||||
self.spread.write({
|
||||
|
||||
@@ -22,11 +22,13 @@ class AccountSpreadInvoiceLineLinkWizard(models.TransientModel):
|
||||
('in_invoice', 'Vendor Bill'),
|
||||
('out_refund', 'Customer Credit Note'),
|
||||
('in_refund', 'Vendor Credit Note')],
|
||||
compute='_compute_invoice_type')
|
||||
compute='_compute_invoice_type',
|
||||
store=True)
|
||||
spread_type = fields.Selection([
|
||||
('sale', 'Customer'),
|
||||
('purchase', 'Supplier')],
|
||||
compute='_compute_invoice_type')
|
||||
compute='_compute_invoice_type',
|
||||
store=True)
|
||||
spread_id = fields.Many2one(
|
||||
'account.spread',
|
||||
string='Spread Board')
|
||||
@@ -45,14 +47,10 @@ class AccountSpreadInvoiceLineLinkWizard(models.TransientModel):
|
||||
spread_account_id = fields.Many2one(
|
||||
'account.account',
|
||||
string='Balance sheet account / Spread account',
|
||||
compute='_compute_spread_journal_account',
|
||||
inverse='_inverse_spread_journal_account',
|
||||
store=True)
|
||||
spread_journal_id = fields.Many2one(
|
||||
'account.journal',
|
||||
string='Spread Journal',
|
||||
compute='_compute_spread_journal_account',
|
||||
inverse='_inverse_spread_journal_account',
|
||||
store=True)
|
||||
|
||||
@api.depends('invoice_line_id')
|
||||
@@ -65,8 +63,8 @@ class AccountSpreadInvoiceLineLinkWizard(models.TransientModel):
|
||||
else:
|
||||
wizard.spread_type = 'purchase'
|
||||
|
||||
@api.depends('company_id', 'invoice_type')
|
||||
def _compute_spread_journal_account(self):
|
||||
@api.onchange('company_id', 'invoice_type')
|
||||
def _onchange_spread_journal_account(self):
|
||||
for wizard in self:
|
||||
company = wizard.company_id
|
||||
acc_revenue = company.default_spread_revenue_account_id
|
||||
|
||||
Reference in New Issue
Block a user