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

[ADD] account_fiscal_position_product #372

Merged
merged 2 commits into from
Nov 28, 2023
Merged
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
70 changes: 70 additions & 0 deletions account_fiscal_position_product/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
=================================
Account Fiscal Position - Product
=================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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-OCA%2Faccount--fiscal--rule-lightgray.png?logo=github
:target: https://github.com/OCA/account-fiscal-rule/tree/12.0/account_fiscal_position_product
:alt: OCA/account-fiscal-rule
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-fiscal-rule-12-0/account-fiscal-rule-12-0-account_fiscal_position_product
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/93/12.0
:alt: Try me on Runbot

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

Allow to configure products in the Fiscal Position tax lines.

When the fiscal position is applied, the taxes are mapped only if the product or its category is configured in the tax line.

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-fiscal-rule/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/account-fiscal-rule/issues/new?body=module:%20account_fiscal_position_product%0Aversion:%2012.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
~~~~~~~

* TAKOBI

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

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/account-fiscal-rule <https://github.com/OCA/account-fiscal-rule/tree/12.0/account_fiscal_position_product>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions account_fiscal_position_product/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
20 changes: 20 additions & 0 deletions account_fiscal_position_product/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2022 Simone Rubino - TAKOBI
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
'name': 'Account Fiscal Position - Product',
'summary': 'Apply fiscal position only for configured products',
'version': '12.0.1.0.0',
'category': 'Accounting',
'author': 'TAKOBI, Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/account-fiscal-rule'
'/tree/12.0/account_fiscal_position_product',
'license': 'AGPL-3',
'development_status': 'Beta',
'depends': [
'account',
],
'data': [
'views/account_fiscal_position_views.xml',
],
}
36 changes: 36 additions & 0 deletions account_fiscal_position_product/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_fiscal_position_product
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-11-23 14:39+0000\n"
"PO-Revision-Date: 2022-11-23 14:39+0000\n"
"Last-Translator: Simone Rubino <[email protected]>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: account_fiscal_position_product
#: model:ir.model,name:account_fiscal_position_product.model_account_fiscal_position
msgid "Fiscal Position"
msgstr "Posizione fiscale"

#. module: account_fiscal_position_product
#: model:ir.model.fields,field_description:account_fiscal_position_product.field_account_fiscal_position_tax__product_category_ids
msgid "Product Categories"
msgstr "Categorie prodotto"

#. module: account_fiscal_position_product
#: model:ir.model.fields,field_description:account_fiscal_position_product.field_account_fiscal_position_tax__product_ids
msgid "Products"
msgstr "Prodotti"

#. module: account_fiscal_position_product
#: model:ir.model,name:account_fiscal_position_product.model_account_fiscal_position_tax
msgid "Tax Mapping of Fiscal Position"
msgstr "Mappatura imposta per la posizione fiscale"
4 changes: 4 additions & 0 deletions account_fiscal_position_product/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import account_fiscal_position
from . import account_fiscal_position_tax
40 changes: 40 additions & 0 deletions account_fiscal_position_product/models/account_fiscal_position.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2022 Simone Rubino - TAKOBI
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models


class AccountFiscalPosition (models.Model):
_inherit = 'account.fiscal.position'

def is_product_fiscal_position(self):
"""
True if any tax mapping in `self.tax_ids`
has a product or a product category.
"""
tax_mappings = self.mapped('tax_ids')
return tax_mappings.is_product_tax_mapping()

@api.model
def map_tax(self, taxes, product=None, partner=None):
"""
If this is a product fiscal position,
only apply tax mappings matching `product`.
Otherwise, return the usual mapping (defined in `super`).
"""
if self.is_product_fiscal_position():
if product is not None:
matching_tax_mappings = self.tax_ids.filtered(
lambda tax_mapping: tax_mapping.match_product(product)
)
if matching_tax_mappings:
result = matching_tax_mappings.map_taxes(taxes)
else:
# No mapping matching `product`: return original taxes
result = taxes
else:
# No `product`: return original taxes
result = taxes
else:
result = super().map_tax(taxes, product=product, partner=partner)
return result
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright 2022 Simone Rubino - TAKOBI
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class AccountFiscalPositionTax (models.Model):
_inherit = 'account.fiscal.position.tax'

product_ids = fields.Many2many(
comodel_name='product.product',
string="Products",
)
product_category_ids = fields.Many2many(
comodel_name='product.category',
string="Product Categories",
)

@api.multi
def is_product_tax_mapping(self):
"""
True if any tax mapping in `self`
has a product or a product category.
"""
for tax_mapping in self:
if tax_mapping.product_ids or tax_mapping.product_category_ids:
is_product = True
break
else:
is_product = False
return is_product

@api.multi
def match_product(self, product):
"""
Return the first mapping in `self` that matches `product`.

A mapping matches `product`
when `product` is declared in the mapping,
or when its category is declared in the mapping.
"""
for tax_line in self:
if product in tax_line.product_ids \
or product.categ_id in tax_line.product_category_ids:
break
else:
tax_line = self.browse()
return tax_line

def map_taxes(self, taxes):
"""
Map each tax in `taxes` using mappings in `self`.

When a tax matches `tax_src_id`,
then `tax_dest_id` is its mapped tax,
otherwise the tax is mapped to itself.
"""
result = self.env['account.tax'].browse()
for tax in taxes:
for tax_mapping in self:
tax_src = tax_mapping.tax_src_id
tax_dest = tax_mapping.tax_dest_id
if tax_src == tax and tax_dest:
result |= tax_dest
break
else:
# No mapping matching `tax`: return original tax
result |= tax

Check warning on line 68 in account_fiscal_position_product/models/account_fiscal_position_tax.py

View check run for this annotation

Codecov / codecov/patch

account_fiscal_position_product/models/account_fiscal_position_tax.py#L68

Added line #L68 was not covered by tests
return result
3 changes: 3 additions & 0 deletions account_fiscal_position_product/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Allow to configure products in the Fiscal Position tax lines.

When the fiscal position is applied, the taxes are mapped only if the product or its category is configured in the tax line.
Loading
Loading