Browse Source

depends on pos_cash_move_reason

pull/449/head
Jordi Ballester Alomar 5 years ago
committed by Adrià Gil Sorribes
parent
commit
3389ef782e
  1. 2
      pos_statement_closing_balance/__manifest__.py
  2. 4
      pos_statement_closing_balance/models/account_journal.py
  3. 2
      pos_statement_closing_balance/models/pos_session.py
  4. 3
      pos_statement_closing_balance/readme/CONFIGURATION.rst
  5. 41
      pos_statement_closing_balance/tests/test_pos_statement_closing_balance.py
  6. 3
      pos_statement_closing_balance/views/account_journal_views.xml
  7. 27
      pos_statement_closing_balance/wizards/pos_update_statement_closing_balance.py
  8. 1
      pos_statement_closing_balance/wizards/pos_update_statement_closing_balance.xml

2
pos_statement_closing_balance/__manifest__.py

@ -11,7 +11,7 @@
'website': 'http://www.github.com/OCA/pos', 'website': 'http://www.github.com/OCA/pos',
'license': 'AGPL-3', 'license': 'AGPL-3',
'depends': [ 'depends': [
'pos_cash_box_journal',
'pos_cash_move_reason',
], ],
'data': [ 'data': [
'wizards/pos_update_statement_closing_balance.xml', 'wizards/pos_update_statement_closing_balance.xml',

4
pos_statement_closing_balance/models/account_journal.py

@ -8,3 +8,7 @@ class AccountJournal(models.Model):
pos_control_ending_balance = fields.Boolean( pos_control_ending_balance = fields.Boolean(
'Control ending balance in POS') 'Control ending balance in POS')
pos_move_reason_id = fields.Many2one(
string='Default reason POS adjustments',
comodel_name='pos.move.reason',
)

2
pos_statement_closing_balance/models/pos_session.py

@ -1,6 +1,6 @@
# Copyright 2020 ForgeFlow, S.L. # Copyright 2020 ForgeFlow, S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models, _
from odoo import api, models, _
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError

3
pos_statement_closing_balance/readme/CONFIGURATION.rst

@ -1,3 +1,4 @@
* Go to *Invoicing > Configuration > Journals* and set, for each Journal * Go to *Invoicing > Configuration > Journals* and set, for each Journal
that will be used in the POS, the flag 'Control ending balance in POS' if that will be used in the POS, the flag 'Control ending balance in POS' if
you expect users to enter the ending balance.
you expect users to enter the ending balance, and enter the default POS
move reason to be used in the adjustment.

41
pos_statement_closing_balance/tests/test_pos_statement_closing_balance.py

@ -8,28 +8,47 @@ class TestPosStatementClosingBalance(TransactionCase):
def setUp(self): def setUp(self):
super(TestPosStatementClosingBalance, self).setUp() super(TestPosStatementClosingBalance, self).setUp()
self.pos_config = self.env["pos.config"].create({"name": "PoS config"}) self.pos_config = self.env["pos.config"].create({"name": "PoS config"})
bank_journal = self.env["account.journal"].create({
self.wizard_reason = self.env['wizard.pos.move.reason']
account = self.env['account.account'].create({
'code': '9999',
'name': 'Test',
'user_type_id': self.env.ref(
"account.data_account_type_liquidity").id
})
self.bank_journal = self.env["account.journal"].create({
"name": "Test bank", "name": "Test bank",
"code": "TB1", "code": "TB1",
"type": "bank", "type": "bank",
"pos_control_ending_balance": True, "pos_control_ending_balance": True,
}) })
self.pos_config.journal_ids += bank_journal
self.pos_move_reason = self.env['pos.move.reason'].create({
'name': 'Bank closing reason',
'is_income_reason': True,
'is_expense_reason': True,
'expense_account_id': account.id,
'income_account_id': account.id,
'journal_ids': self.bank_journal.ids,
'company_id': self.env.ref('base.main_company').id,
})
self.bank_journal.pos_move_reason_id = self.pos_move_reason
self.pos_config.journal_ids += self.bank_journal
self.pos_config.open_session_cb() self.pos_config.open_session_cb()
self.session = self.pos_config.current_session_id self.session = self.pos_config.current_session_id
self.session.action_pos_session_open() self.session.action_pos_session_open()
def test_wizard(self): def test_wizard(self):
journal = self.session.journal_ids.filtered(lambda j: j.code == 'TB1') journal = self.session.journal_ids.filtered(lambda j: j.code == 'TB1')
wizard = (
self.env["cash.box.journal.in"]
.with_context(
active_model="pos.session", active_ids=self.session.ids
)
.create({"amount": 10, "name": "Out"})
)
wizard.journal_id = journal
wizard.run()
wizard = self.wizard_reason.with_context(
active_id=self.session.id,
default_move_type='income').create({
'move_reason_id': self.pos_move_reason.id,
'journal_id': self.bank_journal.id,
'statement_id': self.session.statement_ids.filtered(
lambda s: s.journal_id == self.bank_journal).id,
'amount': 10,
'name': 'Test Bank Deposit',
})
wizard.apply()
self.assertEqual( self.assertEqual(
self.session.statement_ids.filtered( self.session.statement_ids.filtered(
lambda r: r.journal_id.id == journal.id lambda r: r.journal_id.id == journal.id

3
pos_statement_closing_balance/views/account_journal_views.xml

@ -6,7 +6,8 @@
<field name="inherit_id" ref="account.view_account_journal_form"/> <field name="inherit_id" ref="account.view_account_journal_form"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="type" position="after"> <field name="type" position="after">
<field name="pos_control_ending_balance"/>
<field name="pos_control_ending_balance" attrs="{'invisible':[('journal_user', '=', False)]}"/>
<field name="pos_move_reason_id" attrs="{'invisible':[('pos_control_ending_balance', '=', False)]}"/>
</field> </field>
</field> </field>
</record> </record>

27
pos_statement_closing_balance/wizards/pos_update_statement_closing_balance.py

@ -26,6 +26,7 @@ class POSBankStatementUpdateClosingBalance(models.TransientModel):
"balance_start": statement.balance_start, "balance_start": statement.balance_start,
"total_entry_encoding": statement.total_entry_encoding, "total_entry_encoding": statement.total_entry_encoding,
"currency_id": statement.currency_id.id, "currency_id": statement.currency_id.id,
"pos_move_reason_id": statement.journal_id.pos_move_reason_id.id,
} }
@api.model @api.model
@ -53,11 +54,13 @@ class POSBankStatementUpdateClosingBalance(models.TransientModel):
return res return res
@api.model @api.model
def _prepare_cash_box_journal(self, item):
def _prepare_wizard_pos_move_reason(self, item):
return { return {
'move_reason_id':
item.statement_id.journal_id.pos_move_reason_id.id,
'amount': abs(item.difference), 'amount': abs(item.difference),
'name': _('Out'),
"journal_id": item.journal_id.id,
'journal_id': item.journal_id.id,
'name': _("Ending balance adjustment")
} }
@api.multi @api.multi
@ -66,17 +69,19 @@ class POSBankStatementUpdateClosingBalance(models.TransientModel):
for item in self.item_ids: for item in self.item_ids:
if item.difference: if item.difference:
if item.difference > 0.0: if item.difference > 0.0:
model = "cash.box.journal.in"
default_move_type = "income"
else: else:
model = "cash.box.journal.out"
default_move_type = "expense"
wizard = ( wizard = (
self.env[model]
self.env["wizard.pos.move.reason"]
.with_context( .with_context(
active_model="pos.session", active_model="pos.session",
active_ids=self.session_id.ids
).create(self._prepare_cash_box_journal(item))
active_ids=self.session_id.ids,
active_id=self.session_id.id,
default_move_type=default_move_type,
).create(self._prepare_wizard_pos_move_reason(item))
) )
wizard.run()
wizard.apply()
item.statement_id.balance_end_real = item.balance_end_real item.statement_id.balance_end_real = item.balance_end_real
return True return True
@ -112,6 +117,10 @@ class BankStatementLineUpdateEndingBalanceLine(models.TransientModel):
comodel_name='res.currency', comodel_name='res.currency',
related='statement_id.currency_id' related='statement_id.currency_id'
) )
pos_move_reason_id = fields.Many2one(
comodel_name='pos.move.reason',
string='Reason',
)
def _compute_balance_end(self): def _compute_balance_end(self):
for rec in self: for rec in self:

1
pos_statement_closing_balance/wizards/pos_update_statement_closing_balance.xml

@ -14,6 +14,7 @@
<field name="total_entry_encoding"/> <field name="total_entry_encoding"/>
<field name="balance_end_real"/> <field name="balance_end_real"/>
<field name="currency_id" groups="base.group_multi_currency"/> <field name="currency_id" groups="base.group_multi_currency"/>
<field name="pos_move_reason_id" invisible="1"/>
</tree> </tree>
</field> </field>
<footer> <footer>

Loading…
Cancel
Save