Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][ADD] l10n_br_account_service_type_by_partner: add new module #58

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_service_type
from . import res_partner
from . import account_move
from . import account_move_line
26 changes: 26 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,26 @@
# 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_id(self):
super()._onchange_partner_id()
if self.fiscal_operation_type == FISCAL_IN:
for line in self.invoice_line_ids:
if line.product_id:
partner_service_type = (
line.partner_id.partner_service_type_ids.filtered(
lambda x: x.product_id == line.product_id
)
)
if partner_service_type:
line.service_type_id = partner_service_type.service_type_id

Check warning on line 24 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#L24

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

Check warning on line 26 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#L26

Added line #L26 was not covered by tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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_id_fiscal(self):
super()._onchange_product_id_fiscal()
if self.product_id and self.move_id.fiscal_operation_type == FISCAL_IN:
kaynnan marked this conversation as resolved.
Show resolved Hide resolved
partner_service_type = self.partner_id.partner_service_type_ids.filtered(
lambda x: x.product_id == self.product_id
)
if partner_service_type:
self.service_type_id = partner_service_type.service_type_id

Check warning on line 20 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#L20

Added line #L20 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_service_type_ids = fields.One2many(
comodel_name="res.partner.service.type",
inverse_name="partner_id",
string="Partner LC",
)
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 ResPartnerServiceType(models.Model):

_name = "res.partner.service.type"
_description = "Partner Service Type"

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_service_type","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_service_type","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
Loading