diff --git a/tms_account/README.rst b/tms_account/README.rst new file mode 100644 index 000000000..38929e877 --- /dev/null +++ b/tms_account/README.rst @@ -0,0 +1,35 @@ +**This file is going to be generated by oca-gen-addon-readme.** + +*Manual changes will be overwritten.* + +Please provide content in the ``readme`` directory: + +* **DESCRIPTION.rst** (required) +* INSTALL.rst (optional) +* CONFIGURE.rst (optional) +* **USAGE.rst** (optional, highly recommended) +* DEVELOP.rst (optional) +* ROADMAP.rst (optional) +* HISTORY.rst (optional, recommended) +* **CONTRIBUTORS.rst** (optional, highly recommended) +* CREDITS.rst (optional) + +Content of this README will also be drawn from the addon manifest, +from keys such as name, authors, maintainers, development_status, +and license. + +A good, one sentence summary in the manifest is also highly recommended. + + +Automatic changelog generation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`HISTORY.rst` can be auto generated using `towncrier `_. + +Just put towncrier compatible changelog fragments into `readme/newsfragments` +and the changelog file will be automatically generated and updated when a new fragment is added. + +Please refer to `towncrier` documentation to know more. + +NOTE: the changelog will be automatically generated when using `/ocabot merge $option`. +If you need to run it manually, refer to `OCA/maintainer-tools README `_. diff --git a/tms_account/__init__.py b/tms_account/__init__.py new file mode 100644 index 000000000..4fe0a8bcb --- /dev/null +++ b/tms_account/__init__.py @@ -0,0 +1,3 @@ +# Copyright (C) 2024 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import models diff --git a/tms_account/__manifest__.py b/tms_account/__manifest__.py new file mode 100644 index 000000000..89e86675d --- /dev/null +++ b/tms_account/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright (C) 2024 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "TMS - Accounting", + "summary": "Track invoices linked to TMS orders", + "version": "17.0.1.0.0", + "category": "Field Service", + "author": "Open Source Integrators, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-transport", + "depends": ["tms", "account", "tms_sale", "tms_purchase"], + "data": [ + "views/account_move.xml", + "views/tms_order.xml", + ], + "license": "AGPL-3", + "development_status": "Alpha", + "maintainers": ["max3903", "santiagordz", "EdgarRetes"], +} diff --git a/tms_account/models/__init__.py b/tms_account/models/__init__.py new file mode 100644 index 000000000..a6faf7822 --- /dev/null +++ b/tms_account/models/__init__.py @@ -0,0 +1,2 @@ +from . import tms_order +from . import account_move diff --git a/tms_account/models/account_move.py b/tms_account/models/account_move.py new file mode 100644 index 000000000..90bca3fc5 --- /dev/null +++ b/tms_account/models/account_move.py @@ -0,0 +1,31 @@ +# Copyright (C) 2024 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, fields, models + + +class AccountMove(models.Model): + _inherit = "account.move" + + has_tms_order = fields.Boolean(readonly="True", compute="_compute_has_trip") + + @api.depends("line_ids") + def _compute_has_trip(self): + for record in self: + if record.line_ids.sale_line_ids.order_id.tms_order_ids: + record.has_tms_order = True + else: + record.has_tms_order = False + + def action_view_tms_orders(self): + self.ensure_one() + tms_orders = self.line_ids.sale_line_ids.order_id.tms_order_ids + action = self.env["ir.actions.act_window"]._for_xml_id( + "tms.action_tms_dash_order" + ) + if len(tms_orders) > 1: + action["domain"] = [("id", "in", tms_orders.ids)] + else: + action["views"] = [(self.env.ref("tms.tms_order_view_form").id, "form")] + action["res_id"] = tms_orders.id + + return action diff --git a/tms_account/models/tms_order.py b/tms_account/models/tms_order.py new file mode 100644 index 000000000..7511329b1 --- /dev/null +++ b/tms_account/models/tms_order.py @@ -0,0 +1,67 @@ +# Copyright (C) 2024 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import _, api, fields, models + + +class TMSOrder(models.Model): + _inherit = "tms.order" + + invoice_count = fields.Integer( + compute="_compute_get_invoiced", + readonly=True, + copy=False, + ) + bill_count = fields.Integer( + compute="_compute_get_invoiced", + readonly=True, + copy=False, + ) + + create_invoice = fields.Boolean(string="Create invoices and bills when completed?") + + @api.model + def write(self, vals): + super().write(vals) + if "stage_id" in vals: + stage = self.env["tms.stage"].search( + [ + ("id", "=", vals["stage_id"]), + ] + ) + if stage.is_completed and self.create_invoice: + if self.sale_id: + for line in self.sale_id.order_line: + line.qty_delivered = line.product_uom_qty + if not self.sale_id.invoice_ids: + self.sale_id._create_invoices() + if self.purchase_ids: + for purchase in self.purchase_ids: + purchase.action_create_invoice() + return + + @api.depends("stage_id") + def _compute_get_invoiced(self): + for trip in self: + trip.bill_count = 0 + trip.invoice_count = trip.sale_id.invoice_count + + for purchase in trip.purchase_ids: + for line in purchase.order_line: + trip.bill_count += line.qty_invoiced + + def action_view_invoices(self): + action = self.sale_id.action_view_invoice() + return action + + def action_view_bills(self): + self.ensure_one() + return { + "type": "ir.actions.act_window", + "res_model": "account.move", + "view_mode": "tree,form", + "domain": [ + ("line_ids.purchase_line_id.order_id.trip_id", "=", self.id), + ("move_type", "=", "in_invoice"), + ], + "name": _("Bills for Trip %s") % self.name, + } diff --git a/tms_account/pyproject.toml b/tms_account/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/tms_account/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/tms_account/views/account_move.xml b/tms_account/views/account_move.xml new file mode 100644 index 000000000..93d5af491 --- /dev/null +++ b/tms_account/views/account_move.xml @@ -0,0 +1,22 @@ + + + tms.order.invoice.form + account.move + + +
+ +
+
+
+ +
diff --git a/tms_account/views/tms_order.xml b/tms_account/views/tms_order.xml new file mode 100644 index 000000000..e789cf3de --- /dev/null +++ b/tms_account/views/tms_order.xml @@ -0,0 +1,36 @@ + + + tms.order + + + + + + + + + + + +