Skip to content

Commit

Permalink
[ADD] sale_order_type: change of analytical account by project
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasperalta1 committed Dec 18, 2024
1 parent 4a964d3 commit 9ed0a91
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 34 deletions.
54 changes: 27 additions & 27 deletions sale_order_type/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,49 +85,49 @@ Authors
Contributors
------------

- `Vermon <http://www.grupovermon.com>`__
- `Vermon <http://www.grupovermon.com>`__

- Carlos Sánchez Cifuentes <csanchez@grupovermon.com>
- Carlos Sánchez Cifuentes <csanchez@grupovermon.com>

- `AvanzOsc <http://avanzosc.es>`__
- `AvanzOsc <http://avanzosc.es>`__

- Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>
- Ana Juaristi <anajuaristi@avanzosc.es>
- Daniel Campos <danielcampos@avanzosc.es>
- Ainara Galdona <ainaragaldona@avanzosc.es>
- Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>
- Ana Juaristi <anajuaristi@avanzosc.es>
- Daniel Campos <danielcampos@avanzosc.es>
- Ainara Galdona <ainaragaldona@avanzosc.es>

- `Agile Business Group <https://www.agilebg.com>`__
- `Agile Business Group <https://www.agilebg.com>`__

- Lorenzo Battistini <lorenzo.battistini@agilebg.com>
- Lorenzo Battistini <lorenzo.battistini@agilebg.com>

- `Niboo <https://www.niboo.be/>`__
- `Niboo <https://www.niboo.be/>`__

- Samuel Lefever <sam@niboo.be>
- Pierre Faniel <pierre@niboo.be>
- Samuel Lefever <sam@niboo.be>
- Pierre Faniel <pierre@niboo.be>

- `Tecnativa <https://www.tecnativa.com>`__
- `Tecnativa <https://www.tecnativa.com>`__

- Pedro M. Baeza
- David Vidal
- Carlos Dauden
- Sergio Teruel
- Pedro M. Baeza
- David Vidal
- Carlos Dauden
- Sergio Teruel

- `Pesol <https://www.pesol.es>`__
- `Pesol <https://www.pesol.es>`__

- Angel Moya Pardo <angel.moya@pesol.es>
- Antonio J Rubio Lorente <antonio.rubio@pesol.es>
- Angel Moya Pardo <angel.moya@pesol.es>
- Antonio J Rubio Lorente <antonio.rubio@pesol.es>

- Rattapong Chokmasermkul <rattapongc@ecosoft.co.th>
- `Druidoo <https://www.druidoo.io>`__
- Rattapong Chokmasermkul <rattapongc@ecosoft.co.th>
- `Druidoo <https://www.druidoo.io>`__

- Iván Todorovich <ivan.todorovich@druidoo.io>
- Iván Todorovich <ivan.todorovich@druidoo.io>

- `GSLab.it <https://www.gslab.it>`__
- `GSLab.it <https://www.gslab.it>`__

- Giovanni Serra <giovanni@gslab.it>
- Giovanni Serra <giovanni@gslab.it>

- Tharathip Chaweewongphan <tharathipc@ecosoft.co.th>
- Isaac Gallart <igallart@puntsistemes.es>
- Tharathip Chaweewongphan <tharathipc@ecosoft.co.th>
- Isaac Gallart <igallart@puntsistemes.es>

Do not contact contributors directly about support or help with
technical issues.
Expand Down
2 changes: 1 addition & 1 deletion sale_order_type/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sale-workflow",
"license": "AGPL-3",
"depends": ["sale_stock", "account", "sale_management"],
"depends": ["sale_stock", "account", "sale_management", "project"],
"demo": ["demo/sale_order_demo.xml"],
"data": [
"security/ir.model.access.csv",
Expand Down
10 changes: 10 additions & 0 deletions sale_order_type/models/sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class SaleOrder(models.Model):
compute="_compute_picking_policy", store=True, readonly=False
)
incoterm = fields.Many2one(compute="_compute_incoterm", store=True, readonly=False)
project_id = fields.Many2one(
compute="_compute_project_id", store=True, readonly=False
)

@api.model
def _default_type_id(self):
Expand Down Expand Up @@ -124,6 +127,13 @@ def _compute_incoterm(self):
order.incoterm = order_type.incoterm_id
return res

@api.depends("type_id")
def _compute_project_id(self):
for order in self.filtered("type_id"):
order_type = order.type_id
if order_type.project_id:
order.project_id = order_type.project_id

@api.depends("type_id")
def _compute_validity_date(self):
res = super()._compute_validity_date()
Expand Down
9 changes: 5 additions & 4 deletions sale_order_type/models/sale_order_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ class SaleOrderTypology(models.Model):
ondelete="restrict",
check_company=True,
)
analytic_account_id = fields.Many2one(
comodel_name="account.analytic.account",
string="Analytic account",
check_company=True,
project_id = fields.Many2one(
comodel_name="project.project",
domain=[("allow_billable", "=", True)],
string="Project",
help="Select to define the analytics account (new approach in v18)",
)
active = fields.Boolean(default=True)
quotation_validity_days = fields.Integer(string="Quotation Validity (Days)")
Expand Down
7 changes: 7 additions & 0 deletions sale_order_type/tests/test_sale_order_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def setUp(self):
self.sale_pricelist = self.env["product.pricelist"].create(
{"name": "Public Pricelist", "sequence": 1}
)
self.project_id = self.env["project.project"].create(
{"name": "Project sample"}
)
self.free_carrier = self.env.ref("account.incoterm_FCA")
self.sale_type = self.sale_type_model.create(
{
Expand All @@ -66,6 +69,7 @@ def setUp(self):
"picking_policy": "one",
"payment_term_id": self.immediate_payment.id,
"pricelist_id": self.sale_pricelist.id,
"project_id": self.project_id.id,
"incoterm_id": self.free_carrier.id,
"quotation_validity_days": 10,
}
Expand All @@ -79,6 +83,7 @@ def setUp(self):
"picking_policy": "one",
"payment_term_id": self.immediate_payment.id,
"pricelist_id": self.sale_pricelist.id,
"project_id": self.project_id.id,
"incoterm_id": self.free_carrier.id,
}
)
Expand Down Expand Up @@ -125,6 +130,7 @@ def setUp(self):
"picking_policy": "one",
"payment_term_id": self.immediate_payment.id,
"pricelist_id": self.sale_pricelist.id,
"project_id": self.project_id.id,
"incoterm_id": self.free_carrier.id,
"route_id": self.sale_route.id,
}
Expand Down Expand Up @@ -158,6 +164,7 @@ def test_sale_order_flow(self):
self.assertEqual(order.picking_policy, sale_type.picking_policy)
self.assertEqual(order.payment_term_id, sale_type.payment_term_id)
self.assertEqual(order.pricelist_id, sale_type.pricelist_id)
self.assertEqual(order.project_id, sale_type.project_id)
self.assertEqual(order.incoterm, sale_type.incoterm_id)
order.action_confirm()
invoice = order._create_invoices()
Expand Down
4 changes: 2 additions & 2 deletions sale_order_type/views/sale_order_type_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
/>
<field name="sequence_id" />
<field
name="analytic_account_id"
groups="analytic.group_analytic_accounting"
name="project_id"
groups="project.group_project_user,analytic.group_analytic_accounting"
/>
</group>
<group>
Expand Down

0 comments on commit 9ed0a91

Please sign in to comment.