Skip to content

Commit

Permalink
[MIG] pos_cash_move_reason: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoniRomera committed Oct 26, 2023
1 parent f443b8d commit 5af2b9d
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 39 deletions.
2 changes: 1 addition & 1 deletion pos_cash_move_reason/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "ACSONE SA/NV," "GRAP," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/pos",
"category": "Point Of sale",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"depends": ["point_of_sale"],
"data": [
Expand Down
4 changes: 2 additions & 2 deletions pos_cash_move_reason/demo/account_account.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<record id="bank_deposit_account" model="account.account">
<field name="code">101505</field>
<field name="name">Cash Awaiting Bank Deposit</field>
<field name="user_type_id" ref="account.data_account_type_liquidity" />
<field name="account_type">asset_cash</field>
</record>
<record id="gazoline_expense_account" model="account.account">
<field name="code">221500</field>
<field name="name">Gazoline Expense</field>
<field name="user_type_id" ref="account.data_account_type_expenses" />
<field name="account_type">expense</field>
</record>
</odoo>
4 changes: 3 additions & 1 deletion pos_cash_move_reason/models/pos_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ def _button_move_reason(self, move_type):
.sudo()
.read()[0]
)
action["context"] = {"default_move_type": move_type}
action["context"] = {
"default_move_type": move_type,
}
return action
22 changes: 6 additions & 16 deletions pos_cash_move_reason/tests/test_pos_cash_move_reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,19 @@ def test_onchange_expense_reason(self):

def test_take_money(self):
# Open New Session
self.config.open_session_cb()
self.config.open_existing_session_cb()
session = self.PosSession.search(
[("state", "=", "opening_control"), ("config_id", "=", self.config.id)]
)

# Get Cash Statement
statement = session.statement_ids.filtered(
lambda x: x.journal_id == self.cash_journal
)

# Take money to put in Bank
wizard = self.WizardReason.with_context(
active_id=session.id, default_move_type="expense"
).create(
{
"move_reason_id": self.deposit_reason.id,
"journal_id": self.cash_journal.id,
"statement_id": statement.id,
"session_id": session.id,
"amount": 500,
"name": "Test Bank Deposit",
}
Expand All @@ -62,25 +57,20 @@ def test_take_money(self):
[
("account_id", "=", self.deposit_reason.expense_account_id.id),
("debit", "=", 500.0),
("id", "in", statement.move_line_ids.ids),
("id", "in", session.statement_line_ids.move_line_ids.ids),
]
)
# I check the created move line from the cash in
self.assertEqual(len(move_line), 1)

def test_take_invalid_amount(self):
# Open New Session
self.config.open_session_cb()
self.config.open_existing_session_cb()
#
session = self.PosSession.search(
[("state", "=", "opening_control"), ("config_id", "=", self.config.id)]
)

# Get Cash Statement
statement = session.statement_ids.filtered(
lambda x: x.journal_id == self.cash_journal
)

# Enter Invalid money
with self.assertRaises(UserError):
self.WizardReason.with_context(
Expand All @@ -89,14 +79,14 @@ def test_take_invalid_amount(self):
{
"move_reason_id": self.deposit_reason.id,
"journal_id": self.cash_journal.id,
"statement_id": statement.id,
"amount": -100,
"session_id": session.id,
"name": "Test Deposit",
}
)

def test_button_put_money(self):
self.config.open_session_cb()
self.config.open_existing_session_cb()
session = self.PosSession.search(
[("state", "=", "opened"), ("config_id", "=", self.config.id)]
)
Expand Down
19 changes: 1 addition & 18 deletions pos_cash_move_reason/wizard/wizard_pos_move_reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ def _default_session_id(self):
readonly=True,
)

statement_id = fields.Many2one(
comodel_name="account.bank.statement",
string="Bank Statement",
compute="_compute_statement_id",
)

journal_ids = fields.Many2many(
comodel_name="account.journal", related="move_reason_id.journal_ids"
)
Expand All @@ -75,17 +69,6 @@ def _check_amount(self):
if any(w.amount <= 0 for w in self):
raise UserError(_("Invalid Amount"))

@api.depends("journal_id", "session_id")
def _compute_statement_id(self):
for wizard in self:
statement = self.env["account.bank.statement"].browse()
if wizard.session_id and wizard.journal_id:
statements = wizard.session_id.statement_ids.filtered(
lambda x, w=wizard: x.journal_id == w.journal_id
)
statement = fields.first(statements)
wizard.statement_id = statement

def apply(self):
self.ensure_one()
AccountBankStatementLine = self.env["account.bank.statement.line"]
Expand All @@ -101,7 +84,7 @@ def _prepare_statement_line(self):
account_id = self.move_reason_id.expense_account_id.id
return {
"date": fields.Date.context_today(self),
"statement_id": self.statement_id.id,
"pos_session_id": self.session_id.id,
"journal_id": self.journal_id.id,
"amount": amount,
"payment_ref": f"{self.session_id.name} - {self.name}",
Expand Down
1 change: 0 additions & 1 deletion pos_cash_move_reason/wizard/wizard_pos_move_reason.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
name="journal_id"
attrs="{'invisible': [('move_reason_id', '=', False)]}"
/>
<field name="statement_id" invisible="1" />
<field name="journal_ids" invisible="1" />
<field name="name" />
<field name="amount" />
Expand Down
6 changes: 6 additions & 0 deletions setup/pos_cash_move_reason/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 5af2b9d

Please sign in to comment.