-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2b9878
commit ff8363c
Showing
9 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <https://pypi.org/project/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 <https://github.com/OCA/maintainer-tools>`_. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import tms_order | ||
from . import account_move |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[build-system] | ||
requires = ["whool"] | ||
build-backend = "whool.buildapi" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<odoo> | ||
<record id="account_invoice_form" model="ir.ui.view"> | ||
<field name="name">tms.order.invoice.form</field> | ||
<field name="model">account.move</field> | ||
<field name="inherit_id" ref="account.view_move_form" /> | ||
<field name="arch" type="xml"> | ||
<div name="button_box" position="inside"> | ||
<field name="has_tms_order" invisible="1" /> | ||
<button | ||
name="action_view_tms_orders" | ||
type="object" | ||
class="oe_stat_button" | ||
icon="fa-truck" | ||
groups="tms.group_tms_user" | ||
string="TMS Trip" | ||
invisible="not has_tms_order" | ||
/> | ||
</div> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<odoo> | ||
<record id="view_tms_order_form_inherit_account" model="ir.ui.view"> | ||
<field name="model">tms.order</field> | ||
<field name="inherit_id" ref="tms.tms_order_view_form" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//div[@name='button_box']" position="inside"> | ||
<button | ||
name="action_view_invoices" | ||
type="object" | ||
class="oe_stat_button" | ||
icon="fa-pencil-square-o" | ||
invisible="invoice_count == 0" | ||
groups="account.group_account_invoice" | ||
> | ||
<field name="invoice_count" widget="statinfo" string="Invoices" /> | ||
</button> | ||
<button | ||
name="action_view_bills" | ||
type="object" | ||
class="oe_stat_button" | ||
icon="fa-file-text-o" | ||
invisible="bill_count == 0" | ||
groups="account.group_account_invoice" | ||
> | ||
<field name="bill_count" widget="statinfo" string="Bills" /> | ||
</button> | ||
</xpath> | ||
<xpath expr="//field[@name='driver_id']" position="after"> | ||
<field | ||
name="create_invoice" | ||
invisible="not sale_id and not purchase_ids" | ||
/> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |