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 ccffca7
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 33 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: 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
14 changes: 1 addition & 13 deletions pos_cash_move_reason/tests/test_pos_cash_move_reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,13 @@ def test_take_money(self):
[("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,
"amount": 500,
"name": "Test Bank Deposit",
}
Expand All @@ -62,7 +56,7 @@ 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
Expand All @@ -76,11 +70,6 @@ def test_take_invalid_amount(self):
[("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,7 +78,6 @@ 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,
"name": "Test Deposit",
}
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
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 ccffca7

Please sign in to comment.