Skip to content

Commit

Permalink
[ADD] l10n_br_account_service_type_by_partner: add new module
Browse files Browse the repository at this point in the history
  • Loading branch information
kaynnan committed Mar 15, 2024
1 parent b7087b3 commit 73506cd
Show file tree
Hide file tree
Showing 19 changed files with 703 additions and 0 deletions.
74 changes: 74 additions & 0 deletions l10n_br_account_service_type_by_partner/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
=========================================
Brazilian Account Service Type by Partner
=========================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:77a1e6d27b13f6aed543f8a625e448d61cf693fb373faff8de4912bbfa8806b2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-Escodoo%2Fl10n--brazil-lightgray.png?logo=github
:target: https://github.com/Escodoo/l10n-brazil/tree/14.0/l10n_br_account_service_type_by_partner
:alt: Escodoo/l10n-brazil

|badge1| |badge2| |badge3|

The module enables partners to define a service type related to them for a specific product. This provides additional flexibility, allowing the service associated with a product to be determined by the partner, rather than solely relying on the service type defined for the product.

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module, you need to:

* Navigate to Fiscal > Configurations > Service Type LC.
* Choose a service type and mark the option "can_be_selected_on_partner."
* Proceed to the partner's profile.
* Access the Fiscal tab.
* Under "Service Type," assign the chosen service type and product.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/Escodoo/l10n-brazil/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/Escodoo/l10n-brazil/issues/new?body=module:%20l10n_br_account_service_type_by_partner%0Aversion:%2014.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.

Credits
=======

Authors
~~~~~~~

* Escodoo

Contributors
~~~~~~~~~~~~

* `Escodoo <https://www.escodoo.com.br>`_:

* Marcel Savegnago <[email protected]>
* Kaynnan Lemes <[email protected]>

Maintainers
~~~~~~~~~~~

This module is part of the `Escodoo/l10n-brazil <https://github.com/Escodoo/l10n-brazil/tree/14.0/l10n_br_account_service_type_by_partner>`_ project on GitHub.

You are welcome to contribute.
1 change: 1 addition & 0 deletions l10n_br_account_service_type_by_partner/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions l10n_br_account_service_type_by_partner/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2024 - TODAY, Escodoo
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Brazilian Account Service Type by Partner",
"summary": """
Brazilian Account Service Type by Partner""",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"author": "Escodoo, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-brazil",
"depends": ["l10n_br_account"],
"data": [
"views/res_partner_view.xml",
"views/service_type_view.xml",
"security/ir.model.access.csv",
],
}
5 changes: 5 additions & 0 deletions l10n_br_account_service_type_by_partner/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import service_type
from . import res_partner_lc
from . import res_partner
from . import account_move
from . import account_move_line
23 changes: 23 additions & 0 deletions l10n_br_account_service_type_by_partner/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2024 - TODAY, Kaynnan Lemes <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models

from odoo.addons.l10n_br_fiscal.constants.fiscal import FISCAL_IN


class AccountMove(models.Model):
_inherit = "account.move"

@api.onchange("partner_id")
def _onchange_partner_service_type(self):
if self.fiscal_operation_type == FISCAL_IN:
for line in self.invoice_line_ids:
if line.product_id:
partner_lc = line.partner_id.partner_lc_ids.filtered(
lambda lc: lc.product_id == line.product_id
)
if partner_lc:
line.service_type_id = partner_lc.service_type_id

Check warning on line 21 in l10n_br_account_service_type_by_partner/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account_service_type_by_partner/models/account_move.py#L21

Added line #L21 was not covered by tests
else:
line.service_type_id = line.product_id.service_type_id

Check warning on line 23 in l10n_br_account_service_type_by_partner/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account_service_type_by_partner/models/account_move.py#L23

Added line #L23 was not covered by tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 - TODAY, Kaynnan Lemes <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models

from odoo.addons.l10n_br_fiscal.constants.fiscal import FISCAL_IN


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

@api.onchange("product_id")
def _onchange_product_service_type(self):
if self.product_id and self.move_id.fiscal_operation_type == FISCAL_IN:
partner_lc = self.partner_id.partner_lc_ids.filtered(
lambda lc: lc.product_id == self.product_id
)
if partner_lc:
self.service_type_id = partner_lc.service_type_id

Check warning on line 19 in l10n_br_account_service_type_by_partner/models/account_move_line.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_account_service_type_by_partner/models/account_move_line.py#L19

Added line #L19 was not covered by tests
else:
self.service_type_id = self.product_id.service_type_id
15 changes: 15 additions & 0 deletions l10n_br_account_service_type_by_partner/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2024 - TODAY, Kaynnan Lemes <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResPartner(models.Model):

_inherit = "res.partner"

partner_lc_ids = fields.One2many(
comodel_name="res.partner.lc",
inverse_name="partner_id",
string="Partner LC",
)
37 changes: 37 additions & 0 deletions l10n_br_account_service_type_by_partner/models/res_partner_lc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2024 - TODAY, Kaynnan Lemes <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResPartnerLC(models.Model):

_name = "res.partner.lc"
_description = "Fiscal Partner LC"

partner_id = fields.Many2one(
comodel_name="res.partner",
string="Partner",
)

service_type_id = fields.Many2one(
comodel_name="l10n_br_fiscal.service.type",
string="Fiscal Service Type",
domain="[('can_be_selected_on_partner', '=', True)]",
required=True,
)

product_id = fields.Many2one(
comodel_name="product.product",
string="Product",
domain="[('type', '=', 'service'), ('tax_icms_or_issqn', '=', 'issqn')]",
required=True,
)

_sql_constraints = [
(
"unique_product_service_type_partner",
"UNIQUE(product_id, partner_id)",
"A product can only have one service type per partner.",
),
]
11 changes: 11 additions & 0 deletions l10n_br_account_service_type_by_partner/models/service_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2024 - TODAY, Kaynnan Lemes <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ServiceType(models.Model):

_inherit = "l10n_br_fiscal.service.type"

can_be_selected_on_partner = fields.Boolean(string="Can be selected on Partner")
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* `Escodoo <https://www.escodoo.com.br>`_:

* Marcel Savegnago <[email protected]>
* Kaynnan Lemes <[email protected]>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The module enables partners to define a service type related to them for a specific product. This provides additional flexibility, allowing the service associated with a product to be determined by the partner, rather than solely relying on the service type defined for the product.
7 changes: 7 additions & 0 deletions l10n_br_account_service_type_by_partner/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
To use this module, you need to:

* Navigate to Fiscal > Configurations > Service Type LC.
* Choose a service type and mark the option "can_be_selected_on_partner."
* Proceed to the partner's profile.
* Access the Fiscal tab.
* Under "Service Type," assign the chosen service type and product.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
"l10n_br_account_service_type_by_partner_profile_user","Fiscal Partner LC User","model_res_partner_lc","l10n_br_fiscal.group_user",1,0,0,0
"l10n_br_account_service_type_by_partner_profile_manager","Fiscal Partner LC for Manager","model_res_partner_lc","l10n_br_fiscal.group_manager",1,1,1,1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 73506cd

Please sign in to comment.