Skip to content

Commit

Permalink
[REF] Refactore the way prepaid work is invoiced.
Browse files Browse the repository at this point in the history
Add project invoicing typology to ease the configuration of the invoincing on project
Add possibility to configure product to follow the prepaid invoicing workflow, if used, the customer invoice revenue will go in a advanced revenue account and when invoiced from timesheet, an transfert accounting move will be created to put revenue from the advanced revenue account to a refular revenue account
Supplier invoices following the prepaid workflow are set to pay depending on if the paid amounts in the analytic account is positive
  • Loading branch information
florian-dacosta committed Dec 19, 2023
1 parent ab239dd commit 917dd88
Show file tree
Hide file tree
Showing 41 changed files with 1,490 additions and 573 deletions.
1 change: 1 addition & 0 deletions account_invoice_subcontractor/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"views/invoice_view.xml",
"wizard/subcontractor_invoice_work_view.xml",
"views/product_view.xml",
"wizard/res_config_settings.xml",
],
"demo": [
"demo/demo.xml",
Expand Down
1 change: 1 addition & 0 deletions account_invoice_subcontractor/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from . import invoice
from . import product
from . import sale
from . import res_company
3 changes: 0 additions & 3 deletions account_invoice_subcontractor/models/hr.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ def _get_subcontractor_type(self):
required=True,
default="internal",
)
commission_rate = fields.Float(
help="Rate in % for the commission on subcontractor work", default=10.00
)

def _get_employee_invoice_partner(self):
self.ensure_one()
Expand Down
15 changes: 15 additions & 0 deletions account_invoice_subcontractor/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class ResCompany(models.Model):
_inherit = "res.company"

commission_rate = fields.Float(
help="Rate in % for the commission on subcontractor work", default=11.00
)

def _get_commission_rate(self):
self.ensure_one()
return self.commission_rate / 100.0
3 changes: 2 additions & 1 deletion account_invoice_subcontractor/models/subcontractor_work.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def _get_subcontractor_type(self):
# # supplier_invoice_year.name)

def _get_commission_rate(self):
return self.employee_id.commission_rate / 100.0
company = self.invoice_line_id.company_id or self.env.company
return company._get_commission_rate()

@api.depends(
"employee_id",
Expand Down
5 changes: 5 additions & 0 deletions account_invoice_subcontractor/security/security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
<field name="category_id" ref="base.module_category_accounting_and_finance" />
</record>

<record model="res.groups" id="group_project_subcontractor_manager">
<field name="name">Project Invoicing Manager</field>
<field name="category_id" ref="base.module_category_accounting_and_finance" />
</record>

<record id="subcontractor_rule" model="ir.rule">
<field name="name">Subcontractor_rule</field>
<field name="model_id" ref="model_subcontractor_work" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ def setUpClass(cls):
}
)

cls.company_a.write({"commission_rate": 10.0})
cls.customer_a = cls.env["res.partner"].create({"name": "Customer A"})
cls.employee_b = cls.env["hr.employee"].create(
{
"name": "Employee B",
"subcontractor_type": "internal",
"commission_rate": "10.0",
"company_id": cls.company_a.id,
"subcontractor_company_id": cls.company_b.id,
"user_id": cls.user_company_b.id,
Expand Down
1 change: 0 additions & 1 deletion account_invoice_subcontractor/views/hr_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
name="subcontractor_company_id"
attrs="{'required': [('subcontractor_type', '=', 'internal'), ('active', '=', True)], 'invisible': [('subcontractor_type','!=', 'internal')]}"
/>
<field name="commission_rate" />
</group>
</xpath>
</field>
Expand Down
1 change: 1 addition & 0 deletions account_invoice_subcontractor/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import subcontractor_invoice_work
from . import res_config_settings
13 changes: 13 additions & 0 deletions account_invoice_subcontractor/wizard/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

commission_rate = fields.Float(
related="company_id.commission_rate",
readonly=False,
help="Rate in % for the commission on subcontractor work",
)
26 changes: 26 additions & 0 deletions account_invoice_subcontractor/wizard/res_config_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_ecotaxe_res_config_settings" model="ir.ui.view">
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="account.res_config_settings_view_form" />
<field name="arch" type="xml">
<xpath expr="//div[@id='analytic']" position="after">
<h2>Subcontractors</h2>
<div class="row mt16 o_settings_container" id="subonctractor">
<div
class="col-12 col-lg-12 o_setting_box"
id="subcontractor-settings"
>
<div class="o_setting_left_pane" />
<div class="o_setting_right_pane">
<div class="row">
</div>
<label for="commission_rate" class="col-md-5" />
<field name="commission_rate" />
</div>
</div>
</div>
</xpath>
</field>
</record>
</odoo>
14 changes: 12 additions & 2 deletions project_invoicing_subcontractor/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,23 @@
"data": [
"security/ir.model.access.csv",
"wizards/subcontractor_timesheet_invoice_view.xml",
"wizards/supplier_timesheet_invoice_view.xml",
# "wizards/supplier_timesheet_invoice_view.xml",
"views/menu.xml",
"views/account_invoice_view.xml",
"views/hr_timesheet_view.xml",
"views/project_view.xml",
"views/hr_timesheet_sheet.xml",
"views/project_invoice_typology.xml",
"views/product_template.xml",
"views/account_account.xml",
"wizards/res_config_settings.xml",
"data/ir_cron.xml",
],
"demo": [
"demo/account_account.xml",
"demo/product_product.xml",
"demo/project_invoice_typology.xml",
"demo/project_demo.xml",
],
"demo": ["demo/project_demo.xml"],
"installable": True,
}
19 changes: 19 additions & 0 deletions project_invoicing_subcontractor/data/ir_cron.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">

<record forcecreate="True" id="invoice_enough_analytic_amount" model="ir.cron">
<field
name="name"
>Compute subonctractor supplier invoices to pay depending on analytic accounts</field>
<field eval="False" name="active" />
<field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall" />
<field name="state">code</field>
<field name="code">model.compute_enought_analytic_amount_cron()</field>
<field name="model_id" ref="account.model_account_move" />
</record>

</odoo>
42 changes: 42 additions & 0 deletions project_invoicing_subcontractor/demo/account_account.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>

<record id="account_revenue_consulting" model="account.account">
<field name="name">Service Consulting</field>
<field name="code">706140</field>
<field name="user_type_id" ref="account.data_account_type_revenue" />
</record>

<record id="account_revenue_maintenance" model="account.account">
<field name="name">Service Maintenance</field>
<field name="code">706150</field>
<field name="user_type_id" ref="account.data_account_type_revenue" />
</record>

<record id="account_expense_consulting" model="account.account">
<field name="name">Consulting subcontracting</field>
<field name="code">611140</field>
<field name="user_type_id" ref="account.data_account_type_expenses" />
</record>

<record id="account_expense_maintenance" model="account.account">
<field name="name">Maintenance Subcontracting</field>
<field name="code">611150</field>
<field name="user_type_id" ref="account.data_account_type_expenses" />
</record>

<record id="account_expense_internal" model="account.account">
<field name="name">Internal task cost</field>
<field name="code">611160</field>
<field name="user_type_id" ref="account.data_account_type_expenses" />
</record>

<record id="account_prepaid_customer_maintenance" model="account.account">
<field name="name">Prepaid Revenues (maintenance)</field>
<field name="code">418101</field>
<field name="reconcile" eval="False" />
<field name="is_prepaid_account" eval="True" />
<field name="user_type_id" ref="account.data_account_type_current_assets" />
</record>

</odoo>
41 changes: 41 additions & 0 deletions project_invoicing_subcontractor/demo/product_product.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>

<record id="product_product_1" model="product.product">
<field name="name">consulting</field>
<field name="categ_id" ref="product.product_category_3" />
<field name="list_price">500</field>
<field name="type">service</field>
<field name="uom_id" ref="uom.product_uom_day" />
<field name="uom_po_id" ref="uom.product_uom_day" />
<field name="property_account_income_id" ref="account_revenue_consulting" />
<field name="property_account_expense_id" ref="account_expense_consulting" />
<field name="subcontracted" eval="True" />
</record>

<record id="product_product_2" model="product.product">
<field name="name">consulting (maintenance package)</field>
<field name="categ_id" ref="product.product_category_3" />
<field name="list_price">600</field>
<field name="type">service</field>
<field name="uom_id" ref="uom.product_uom_day" />
<field name="uom_po_id" ref="uom.product_uom_day" />
<field name="property_account_income_id" ref="account_revenue_maintenance" />
<field name="property_account_expense_id" ref="account_expense_maintenance" />
<field
name="prepaid_revenue_account_id"
ref="account_prepaid_customer_maintenance"
/>
</record>

<record id="product_product_3" model="product.product">
<field name="name">Internal Task</field>
<field name="categ_id" ref="product.product_category_3" />
<field name="list_price">0</field>
<field name="type">service</field>
<field name="uom_id" ref="uom.product_uom_day" />
<field name="uom_po_id" ref="uom.product_uom_day" />
<field name="property_account_expense_id" ref="account_expense_internal" />
</record>

</odoo>
Loading

0 comments on commit 917dd88

Please sign in to comment.