Skip to content

Commit

Permalink
TA#65669 [ADD] sales_team_account_journal (#380)
Browse files Browse the repository at this point in the history
* TA#65669 [ADD] sales_team_account_journal

* TA#65669 [ADD] sales_team_account_journal

* TA#65669 [ADD] sales_team_account_journal

---------

Co-authored-by: majouda <[email protected]>
  • Loading branch information
lanto-razafindrabe and majouda authored Jun 5, 2024
1 parent 82c57cf commit c99523f
Show file tree
Hide file tree
Showing 19 changed files with 264 additions and 0 deletions.
1 change: 1 addition & 0 deletions .docker_files/main/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"sale_warranty_groupby_parent_affiliate",
"sale_whole_order_invoiced",
"sale_xmlrpc_compatible",
"sales_team_account_journal",
"web_view_google_map_itinerary",
"website_payment_message_enhanced",
"website_sale_request_price",
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ COPY sale_warranty /mnt/extra-addons/sale_warranty
COPY sale_warranty_groupby_parent_affiliate /mnt/extra-addons/sale_warranty_groupby_parent_affiliate
COPY sale_whole_order_invoiced /mnt/extra-addons/sale_whole_order_invoiced
COPY sale_xmlrpc_compatible /mnt/extra-addons/sale_xmlrpc_compatible
COPY sales_team_account_journal /mnt/extra-addons/sales_team_account_journal
COPY web_view_google_map_itinerary /mnt/extra-addons/web_view_google_map_itinerary
COPY website_payment_message_enhanced /mnt/extra-addons/website_payment_message_enhanced
COPY website_sale_request_price /mnt/extra-addons/website_sale_request_price
Expand Down
47 changes: 47 additions & 0 deletions sales_team_account_journal/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Sales Team Account Journal
==========================
This module allows to define a default sales journal on a sales team
and assign this sales journal to all invoices linked to this sales team.

Features
--------
**New Sales Journal field on sales team**
As a user in the Sales/Manager group, I go to `Sales > Configuration > Sales Teams`.
I create a new sales team or click on an existing sales team.

.. image:: static/description/sales_team_menu.png

I see that a new `Sales Journal` field is available.

.. image:: static/description/sales_journal_choices.png

On hover, I see that the following help field is available:

.. image:: static/description/sale_journal_helper.png

I select the `Amazon Sale` journal and save.

.. image:: static/description/sales_team_record.png

Usage
-----
As the `Accounting > Billing Administrator` user, I go to a customer sales order
for which the sales team is linked to Amazon Sale journal.
I create the invoice and post it.

.. image:: static/description/invoice_with_sales_team.png

On the draft invoice, I see that the sales journal is Amazon Sale.

.. image:: static/description/customer_invoice_journal.png

Important notes
---------------
-If the sales journal is not set on the sales team, vanilla behavior is applied.
-If the currency of the journal defined on the sales team is different
from the currency of the invoice created, the vanilla behavior applies
(i.e. the system will assign to the invoice the first sales journal that is in the currency of the invoice).

Contributors
------------
* Numigi (tm) and all its contributors (https://bit.ly/numigiens)
4 changes: 4 additions & 0 deletions sales_team_account_journal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
21 changes: 21 additions & 0 deletions sales_team_account_journal/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Sales Team Account Journal",
"version": "1.0.0",
"author": "Numigi",
"maintainer": "Numigi",
"website": "https://bit.ly/numigi-com",
"license": "AGPL-3",
"category": "Sale",
"depends": [
"account",
"sales_team",
],
"summary": "Add a default sales journal on a sales team for invoices",
"data": [
"views/crm_team_views.xml",
],
"installable": True,
}
58 changes: 58 additions & 0 deletions sales_team_account_journal/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sales_team_account_journal
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-05-30 06:03+0000\n"
"PO-Revision-Date: 2024-05-30 06:03+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: sales_team_account_journal
#: model:ir.model.fields,field_description:sales_team_account_journal.field_account_move__display_name
#: model:ir.model.fields,field_description:sales_team_account_journal.field_crm_team__display_name
msgid "Display Name"
msgstr "Nom d'affichage"

#. module: sales_team_account_journal
#: model:ir.model.fields,field_description:sales_team_account_journal.field_account_move__id
#: model:ir.model.fields,field_description:sales_team_account_journal.field_crm_team__id
msgid "ID"
msgstr ""

#. module: sales_team_account_journal
#: model:ir.model,name:sales_team_account_journal.model_account_move
msgid "Journal Entry"
msgstr "Pièce comptable"

#. module: sales_team_account_journal
#: model:ir.model.fields,field_description:sales_team_account_journal.field_account_move____last_update
#: model:ir.model.fields,field_description:sales_team_account_journal.field_crm_team____last_update
msgid "Last Modified on"
msgstr "Dernière modification le"

#. module: sales_team_account_journal
#: model:ir.model.fields,field_description:sales_team_account_journal.field_crm_team__journal_id
msgid "Sales Journal"
msgstr "Journal de ventes"

#. module: sales_team_account_journal
#: model:ir.model,name:sales_team_account_journal.model_crm_team
msgid "Sales Team"
msgstr "Équipe commerciale"

#. module: sales_team_account_journal
#: model:ir.model.fields,help:sales_team_account_journal.field_crm_team__journal_id
msgid ""
"This Sales Journal will be set as default on all Sales related "
"to this Sales Team. Only Sales type journals can be selected."
msgstr ""
"Ce journal de vente sera défini par défaut sur toutes les ventes liées "
"à cette équipe commerciale. Seuls les journaux de type Ventes peuvent être sélectionnés."
5 changes: 5 additions & 0 deletions sales_team_account_journal/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import crm_team
from . import account_move
36 changes: 36 additions & 0 deletions sales_team_account_journal/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models


class AccountMove(models.Model):
_inherit = "account.move"

@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

@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
20 changes: 20 additions & 0 deletions sales_team_account_journal/models/crm_team.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models, fields


class CrmTeam(models.Model):
_inherit = "crm.team"

journal_id = fields.Many2one(
"account.journal",
string="Sales Journal",
ondelete="restrict",
domain=[("type", "=", "sale")],
check_company=True,
help=(
"This Sales Journal will be set as default on all Sales related \
to this Sales Team. Only Sales type journals can be selected.",
),
)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions sales_team_account_journal/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import test__account_move_journal
52 changes: 52 additions & 0 deletions sales_team_account_journal/tests/test__account_move_journal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.tests.common import SavepointCase


class AccountMoveJournal(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.journal = cls.env["account.journal"].create(
{
"name": "My Sale Journal",
"type": "sale",
"code": "MSJ",
"currency_id": cls.env.ref("base.USD").id,
}
)
cls.team_id = cls.env["crm.team"].create(
{
"name": "Super Sales Team",
"journal_id": cls.journal.id,
}
)

def test__01_team_journal_exists(self):
move = self.env["account.move"].create(
{
"team_id": self.team_id.id,
"currency_id": self.env.ref("base.USD").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,
}
)
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.USD").id,
}
)
self.assertNotEqual(move.journal_id.name, self.journal.name)
15 changes: 15 additions & 0 deletions sales_team_account_journal/views/crm_team_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="crm_team_view_form_inherit" model="ir.ui.view">
<field name="name">Add account journal on crm team form view</field>
<field name="model">crm.team</field>
<field name="inherit_id" ref="sales_team.crm_team_view_form"/>
<field name="arch" type="xml">
<xpath expr="//group[@name='right']" position="inside">
<field name="journal_id"/>
</xpath>
</field>
</record>

</odoo>

0 comments on commit c99523f

Please sign in to comment.