Skip to content

Commit

Permalink
[MIG] fieldservice_isp_account: Migration to 13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
baimont committed May 19, 2021
1 parent 960ed0b commit acc98ae
Show file tree
Hide file tree
Showing 16 changed files with 192 additions and 122 deletions.
14 changes: 7 additions & 7 deletions fieldservice_isp_account/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ Field Service - ISP Accounting
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Ffield--service-lightgray.png?logo=github
:target: https://github.com/OCA/field-service/tree/12.0/fieldservice_isp_account
:target: https://github.com/OCA/field-service/tree/13.0/fieldservice_isp_account
:alt: OCA/field-service
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/field-service-12-0/field-service-12-0-fieldservice_isp_account
:target: https://translation.odoo-community.org/projects/field-service-13-0/field-service-13-0-fieldservice_isp_account
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/264/12.0
:target: https://runbot.odoo-community.org/runbot/264/13.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
|badge1| |badge2| |badge3| |badge4| |badge5|

This module adds the ability to track employee time and contractor
costs for Field Service Orders. It also adds functionality to create
Expand Down Expand Up @@ -67,7 +67,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/field-service/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/field-service/issues/new?body=module:%20fieldservice_isp_account%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/field-service/issues/new?body=module:%20fieldservice_isp_account%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -118,8 +118,8 @@ promote its widespread use.

Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-osimallen| |maintainer-brian10048| |maintainer-bodedra|
|maintainer-osimallen| |maintainer-brian10048| |maintainer-bodedra|

This module is part of the `OCA/field-service <https://github.com/OCA/field-service/tree/12.0/fieldservice_isp_account>`_ project on GitHub.
This module is part of the `OCA/field-service <https://github.com/OCA/field-service/tree/13.0/fieldservice_isp_account>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 2 additions & 1 deletion fieldservice_isp_account/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Field Service - ISP Accounting",
"summary": """Invoice Field Service orders based on employee time
or contractor costs""",
"version": "12.0.2.3.2",
"version": "13.0.1.0.0",
"category": "Field Service",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/field-service",
Expand All @@ -15,6 +15,7 @@
"hr_timesheet",
],
"data": [
"security/fsm_order_cost.xml",
"security/ir.model.access.csv",
"data/time_products.xml",
"views/account.xml",
Expand Down
6 changes: 3 additions & 3 deletions fieldservice_isp_account/i18n/es_AR.po
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2020-07-21 05:19+0000\n"
"Last-Translator: Ignacio Buioli <[email protected]>\n"
Expand Down Expand Up @@ -128,7 +128,7 @@ msgid "Hour(s)"
msgstr "Hora(s)"

#. module: fieldservice_isp_account
#: model:ir.model,name:fieldservice_isp_account.model_account_invoice_line
#: model:ir.model,name:fieldservice_isp_account.model_account_move_line
msgid "Invoice Line"
msgstr "Línea de Factura"

Expand Down Expand Up @@ -167,7 +167,7 @@ msgstr ""
" "

#. module: fieldservice_isp_account
#: code:addons/fieldservice_isp_account/models/account_invoice_line.py:19
#: code:addons/fieldservice_isp_account/models/account_move_line.py:19
#, python-format
msgid "Please set the field service worker."
msgstr "Por favor configure el trabajador de servicio de campo."
Expand Down
6 changes: 3 additions & 3 deletions fieldservice_isp_account/i18n/es_CL.po
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2020-01-16 22:38+0000\n"
"Last-Translator: Nelson Ramírez Sánchez <[email protected]>\n"
Expand Down Expand Up @@ -128,7 +128,7 @@ msgid "Hour(s)"
msgstr ""

#. module: fieldservice_isp_account
#: model:ir.model,name:fieldservice_isp_account.model_account_invoice_line
#: model:ir.model,name:fieldservice_isp_account.model_account_move_line
msgid "Invoice Line"
msgstr ""

Expand Down Expand Up @@ -165,7 +165,7 @@ msgid "Overtime for Field Service Employees\n"
msgstr ""

#. module: fieldservice_isp_account
#: code:addons/fieldservice_isp_account/models/account_invoice_line.py:19
#: code:addons/fieldservice_isp_account/models/account_move_line.py:19
#, python-format
msgid "Please set the field service worker."
msgstr ""
Expand Down
6 changes: 3 additions & 3 deletions fieldservice_isp_account/i18n/fieldservice_isp_account.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
Expand Down Expand Up @@ -121,7 +121,7 @@ msgid "Hour(s)"
msgstr ""

#. module: fieldservice_isp_account
#: model:ir.model,name:fieldservice_isp_account.model_account_invoice_line
#: model:ir.model,name:fieldservice_isp_account.model_account_move_line
msgid "Invoice Line"
msgstr ""

Expand Down Expand Up @@ -158,7 +158,7 @@ msgid "Overtime for Field Service Employees\n"
msgstr ""

#. module: fieldservice_isp_account
#: code:addons/fieldservice_isp_account/models/account_invoice_line.py:19
#: code:addons/fieldservice_isp_account/models/account_move_line.py:19
#, python-format
msgid "Please set the field service worker."
msgstr ""
Expand Down
6 changes: 3 additions & 3 deletions fieldservice_isp_account/i18n/pt_BR.po
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2020-06-17 16:19+0000\n"
"Last-Translator: Fernando Colus <[email protected]>\n"
Expand Down Expand Up @@ -128,7 +128,7 @@ msgid "Hour(s)"
msgstr "Hora(s)"

#. module: fieldservice_isp_account
#: model:ir.model,name:fieldservice_isp_account.model_account_invoice_line
#: model:ir.model,name:fieldservice_isp_account.model_account_move_line
msgid "Invoice Line"
msgstr "Linha de Fatura"

Expand Down Expand Up @@ -167,7 +167,7 @@ msgstr ""
" "

#. module: fieldservice_isp_account
#: code:addons/fieldservice_isp_account/models/account_invoice_line.py:19
#: code:addons/fieldservice_isp_account/models/account_move_line.py:19
#, python-format
msgid "Please set the field service worker."
msgstr "Por favor, selecione o trabalhador do serviço de campo."
Expand Down
3 changes: 2 additions & 1 deletion fieldservice_isp_account/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import (
account_invoice_line,
account_move_line,
fsm_order,
fsm_person,
)
from . import fsm_order_cost
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Copyright (C) 2018 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, models
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class AccountInvoiceLine(models.Model):
_inherit = "account.invoice.line"
class AccountMoveLine(models.Model):
_inherit = "account.move.line"

fsm_order_id = fields.Many2one("fsm.order", string="FSM Order")

@api.onchange("product_id", "quantity")
def onchange_product_id(self):
Expand Down Expand Up @@ -35,5 +37,5 @@ def onchange_product_id(self):
supinfo and supinfo[0].price or tmpl.standard_price
)
line.account_id = accounts.get("expense", False)
line.invoice_line_tax_ids = fpos.map_tax(tmpl.supplier_taxes_id)
line.tax_ids = fpos.map_tax(tmpl.supplier_taxes_id)
line.name = line.product_id.name
105 changes: 61 additions & 44 deletions fieldservice_isp_account/models/fsm_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class FSMOrder(models.Model):
_inherit = "fsm.order"

contractor_cost_ids = fields.One2many(
"account.invoice.line", "fsm_order_id", string="Contractor Costs"
"fsm.order.cost", "fsm_order_id", string="Contractor Costs"
)
employee_timesheet_ids = fields.One2many(
"account.analytic.line", "fsm_order_id", string="Employee Timesheets"
Expand All @@ -38,6 +38,8 @@ def _compute_employee(self):
for order in self:
if user.employee_ids:
order.employee = True
else:
order.employee = False

@api.depends("employee_timesheet_ids", "contractor_cost_ids")
def _compute_total_cost(self):
Expand Down Expand Up @@ -68,11 +70,11 @@ def _compute_contractor_cost(self):
def action_complete(self):
for order in self:
order.account_stage = "review"
if self.person_id.supplier and not self.contractor_cost_ids:
if self.person_id.supplier_rank and not self.contractor_cost_ids:
raise ValidationError(
_("Cannot move to Complete " + "until 'Contractor Costs' is filled in")
)
if not self.person_id.supplier and not self.employee_timesheet_ids:
if not self.person_id.supplier_rank and not self.employee_timesheet_ids:
raise ValidationError(
_(
"Cannot move to Complete until "
Expand All @@ -84,7 +86,7 @@ def action_complete(self):
def create_bills(self):
jrnl = self.env["account.journal"].search(
[
("company_id", "=", self.env.user.company_id.id),
("company_id", "=", self.env.company.id),
("type", "=", "purchase"),
("active", "=", True),
],
Expand All @@ -97,16 +99,16 @@ def create_bills(self):
"journal_id": jrnl.id or False,
"fiscal_position_id": fpos.id or False,
"fsm_order_ids": [(4, self.id)],
"company_id": self.env.user.company_id.id,
"company_id": self.env.company.id,
}
bill = self.env["account.invoice"].sudo().create(vals)
bill = self.env["account.move"].sudo().create(vals)
for line in self.contractor_cost_ids:
line.invoice_id = bill
bill.compute_taxes()
line.move_id = bill
bill._recompute_tax_lines()

def account_confirm(self):
for order in self:
contractor = order.person_id.partner_id.supplier
contractor = order.person_id.partner_id.supplier_rank
if order.contractor_cost_ids:
if contractor:
order.create_bills()
Expand All @@ -121,7 +123,7 @@ def account_confirm(self):
def account_create_invoice(self):
jrnl = self.env["account.journal"].search(
[
("company_id", "=", self.env.user.company_id.id),
("company_id", "=", self.env.company.id),
("type", "=", "sale"),
("active", "=", True),
],
Expand All @@ -131,76 +133,91 @@ def account_create_invoice(self):
if not self.customer_id:
raise ValidationError(_("Contact empty"))
fpos = self.customer_id.property_account_position_id
vals = {
invoice_vals = {
"partner_id": self.customer_id.id,
"type": "out_invoice",
"journal_id": jrnl.id or False,
"fiscal_position_id": fpos.id or False,
"fsm_order_ids": [(4, self.id)],
}
invoice = self.env["account.invoice"].sudo().create(vals)
price_list = invoice.partner_id.property_product_pricelist
price_list = self.customer_id.property_product_pricelist

else:
fpos = self.location_id.customer_id.property_account_position_id
vals = {
invoice_vals = {
"partner_id": self.location_id.customer_id.id,
"type": "out_invoice",
"journal_id": jrnl.id or False,
"fiscal_position_id": fpos.id or False,
"fsm_order_ids": [(4, self.id)],
"company_id": self.env.user.company_id.id,
"company_id": self.env.company.id,
}
invoice = self.env["account.invoice"].sudo().create(vals)
price_list = invoice.partner_id.property_product_pricelist
price_list = self.location_id.customer_id.property_product_pricelist

invoice_line_vals = []
for cost in self.contractor_cost_ids:
price = price_list.get_product_price(
product=cost.product_id,
quantity=cost.quantity,
partner=invoice.partner_id,
partner=invoice_vals.get("partner_id"),
date=False,
uom_id=False,
)
template = cost.product_id.product_tmpl_id
accounts = template.get_product_accounts()
account = accounts["income"]
vals = {
"product_id": cost.product_id.id,
"account_analytic_id": cost.account_analytic_id.id,
"quantity": cost.quantity,
"name": cost.name,
"price_unit": price,
"account_id": account.id,
"invoice_id": invoice.id,
"fsm_order_id": self.id,
}
con_cost = self.env["account.invoice.line"].create(vals)
taxes = template.taxes_id
con_cost.invoice_line_tax_ids = fpos.map_tax(taxes)
tax_ids = fpos.map_tax(taxes)
invoice_line_vals.append(
(
0,
0,
{
"product_id": cost.product_id.id,
# "analytic_account_id": cost.analytic_account_id.id,
"quantity": cost.quantity,
"name": cost.product_id.display_name,
"price_unit": price,
"account_id": account.id,
"fsm_order_id": self.id,
"tax_ids": [(6, 0, tax_ids.ids)],
},
)
)
for line in self.employee_timesheet_ids:
price = price_list.get_product_price(
product=line.product_id,
quantity=line.unit_amount,
partner=invoice.partner_id,
partner=invoice_vals.get("partner_id"),
date=False,
uom_id=False,
)
template = line.product_id.product_tmpl_id
accounts = template.get_product_accounts()
account = accounts["income"]
vals = {
"product_id": line.product_id.id,
"account_analytic_id": line.account_id.id,
"quantity": line.unit_amount,
"name": line.name,
"price_unit": price,
"account_id": account.id,
"invoice_id": invoice.id,
"fsm_order_id": self.id,
}
time_cost = self.env["account.invoice.line"].create(vals)
taxes = template.taxes_id
time_cost.invoice_line_tax_ids = fpos.map_tax(taxes)
invoice.compute_taxes()
tax_ids = fpos.map_tax(taxes)
invoice_line_vals.append(
(
0,
0,
{
"product_id": line.product_id.id,
"analytic_account_id": line.account_id.id,
"quantity": line.unit_amount,
"name": line.name,
"price_unit": price,
"account_id": account.id,
"fsm_order_id": self.id,
"tax_ids": [(6, 0, tax_ids.ids)],
},
)
)

invoice_vals.update({"invoice_line_ids": invoice_line_vals})
invoice = self.env["account.move"].sudo().create(invoice_vals)

invoice._recompute_tax_lines()
self.account_stage = "invoiced"
return invoice

Expand Down
Loading

0 comments on commit acc98ae

Please sign in to comment.