Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TA#67501 [FIX] sales_team_account_journal #382

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sales_team_account_journal/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

{
"name": "Sales Team Account Journal",
"version": "1.0.0",
"version": "1.0.1",
"author": "Numigi",
"maintainer": "Numigi",
"website": "https://bit.ly/numigi-com",
"license": "AGPL-3",
"category": "Sale",
"depends": [
"account",
"sale",
"sales_team",
],
"summary": "Add a default sales journal on a sales team for invoices",
Expand Down
49 changes: 27 additions & 22 deletions sales_team_account_journal/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,35 @@
class AccountMove(models.Model):
_inherit = "account.move"

def _check_team_journal(self, team_id, company_id, currency_id):
return (
True
if team_id.journal_id
and team_id.journal_id.company_id.id == company_id
and team_id.journal_id.currency_id.id == currency_id
else False
)

def _check_sale_move_type(self):
move_type = self._context.get('default_move_type', 'entry')
return True if move_type in self.get_sale_types(include_receipts=False) else False

@api.onchange("team_id")
def onchange_team_id(self):
if (
self.team_id
and self.team_id.journal_id
and (
not self.team_id.journal_id.currency_id
or self.team_id.journal_id.currency_id == self.currency_id
)
and self.team_id.journal_id.company_id == self.company_id
):
self.journal_id = self.team_id.journal_id
if self.team_id:
if self._check_sale_move_type() and self._check_team_journal(
self.team_id, self.company_id.id, self.currency_id.id
):
self.journal_id = self.team_id.journal_id

@api.model
def create(self, vals):
rec = super(AccountMove, self).create(vals)
if (
rec.team_id
and rec.team_id.journal_id
and (
not rec.team_id.journal_id.currency_id
or rec.team_id.journal_id.currency_id == rec.currency_id
)
and rec.team_id.journal_id.company_id == rec.company_id
):
rec.journal_id = rec.team_id.journal_id.id
return rec
if vals.get("team_id", False):
team_id = self.env["crm.team"].browse(vals["team_id"])
company_id = vals.get("company_id", self.env.company.id)
currency_id = vals.get("currency_id", False)
if self._check_sale_move_type() and self._check_team_journal(
team_id, company_id, currency_id
):
vals["journal_id"] = team_id.journal_id.id
return super(AccountMove, self).create(vals)
43 changes: 32 additions & 11 deletions sales_team_account_journal/tests/test__account_move_journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,66 @@ class AccountMoveJournal(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.company_id = cls.env.ref("base.main_company")
cls.client_id = cls.env["res.partner"].create({"name": "My Client"})
cls.journal = cls.env["account.journal"].create(
{
"name": "My Sale Journal",
"type": "sale",
"code": "MSJ",
"currency_id": cls.env.ref("base.USD").id,
"company_id": cls.company_id.id,
}
)
cls.team_id = cls.env["crm.team"].create(
{
"name": "Super Sales Team",
"journal_id": cls.journal.id,
}
)
cls.team_id = cls.env.ref("sales_team.team_sales_department")

def test__01_team_journal_exists(self):
move = self.env["account.move"].create(
self.team_id.write(
{
"team_id": self.team_id.id,
"currency_id": self.env.ref("base.USD").id,
"company_id": self.company_id.id,
"journal_id": self.journal.id,
}
)
move = (
self.env["account.move"]
.with_context(default_move_type="out_invoice")
.create(
{
"ref": "test_invoice_1",
"partner_id": self.client_id.id,
"currency_id": self.env.ref("base.USD").id,
"company_id": self.company_id.id,
"team_id": self.team_id.id,
}
)
)

self.assertEqual(move.journal_id.name, self.journal.name)

def test__02_team_journal_not_exists(self):
self.team_id.journal_id = False
move = self.env["account.move"].create(
{
"currency_id": self.env.ref("base.USD").id,
"move_type": "out_invoice",
}
)
self.assertNotEqual(move.journal_id, self.journal)

def test__03_team_journal_exists_but_different_currency(self):
self.journal.currency_id = self.env.ref("base.EUR").id
move = self.env["account.move"].create(
{
"team_id": self.team_id.id,
"currency_id": self.env.ref("base.EUR").id,
"move_type": "out_invoice",
}
)
self.assertNotEqual(move.journal_id.name, self.journal.name)

def test__04_in_invoice_journal_not_changed_by_team(self):
move = self.env["account.move"].create(
{
"currency_id": self.env.ref("base.USD").id,
"move_type": "entry",
}
)
self.assertNotEqual(move.journal_id.name, self.journal.name)
Loading