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

16.0 add main matrice documentation #3

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f2c82ad
[FIX] typo
legalsylvain Nov 21, 2024
e5950fa
[IMP] Make import available at template level
legalsylvain Nov 21, 2024
af4bb26
[FIX] Import changed. refactoring errors
legalsylvain Nov 21, 2024
af9fce2
[REF] Test import for product.product and product.template
legalsylvain Nov 21, 2024
bf4495a
[TMP] disable failing test
legalsylvain Nov 21, 2024
448a743
[WIP] restore product.product test
legalsylvain Nov 21, 2024
014d1d4
[REF] finish to refactor product / template
legalsylvain Nov 21, 2024
845d6f9
[REF] Remove standard_price computation. should be done in the Calc file
legalsylvain Nov 21, 2024
e6221e9
[REF] name of module.
legalsylvain Nov 21, 2024
1dee2a1
[REF] Simplify test files
legalsylvain Nov 22, 2024
d19322d
[ADD] grap_custom_import_product_pos + recurring creation
legalsylvain Nov 22, 2024
fc241cf
[REF] move create_recursive_mixin in dedicated modules
legalsylvain Nov 22, 2024
5b1af4b
[REM] grap_custom_import_product_pos
legalsylvain Nov 22, 2024
e215787
[IMP] add grap_import_supplier_invoice_qty
legalsylvain Nov 22, 2024
1bc50e1
[ADD] grap_custom_import_purchase_discount module
legalsylvain Nov 22, 2024
b1eb0fa
[ADD] grap_custom_import_purchase_triple_discount
legalsylvain Nov 22, 2024
2878f07
[ADD] template
legalsylvain Nov 22, 2024
24db47e
[REM] demo file
legalsylvain Nov 22, 2024
c2d8592
[REF] Rename modules
legalsylvain Nov 22, 2024
f4bd6eb
[ADD] fermente_custom_import_demo module
legalsylvain Nov 24, 2024
96ea26a
[ADD] fermente_custom_import_product_label
legalsylvain Nov 24, 2024
2845b34
[ADD] fermente_custom_import_product_margin_classification
legalsylvain Nov 25, 2024
27f6d49
[IMP] fermente_custom_import_account_product_fiscal_classification: h…
legalsylvain Nov 26, 2024
0b0a4c7
[UPDATE] template file
legalsylvain Nov 26, 2024
3eccf28
[ADD] fermente_custom_import_partner_firstname
legalsylvain Nov 26, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ GRAP - Custom Import Fiscal Classification
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-grap%2Fgrap--odoo--import-lightgray.png?logo=github
:target: https://github.com/grap/grap-odoo-import/tree/16.0/grap_custom_import_account_product_fiscal_classification
:target: https://github.com/grap/grap-odoo-import/tree/16.0/fermente_custom_import_account_product_fiscal_classification
:alt: grap/grap-odoo-import

|badge1| |badge2| |badge3|
Expand Down Expand Up @@ -45,7 +45,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/grap/grap-odoo-import/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/grap/grap-odoo-import/issues/new?body=module:%20grap_custom_import_account_product_fiscal_classification%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/grap/grap-odoo-import/issues/new?body=module:%20fermente_custom_import_account_product_fiscal_classification%0Aversion:%2016.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 All @@ -65,6 +65,6 @@ Contributors
Maintainers
~~~~~~~~~~~

This module is part of the `grap/grap-odoo-import <https://github.com/grap/grap-odoo-import/tree/16.0/grap_custom_import_account_product_fiscal_classification>`_ project on GitHub.
This module is part of the `grap/grap-odoo-import <https://github.com/grap/grap-odoo-import/tree/16.0/fermente_custom_import_account_product_fiscal_classification>`_ project on GitHub.

You are welcome to contribute.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "GRAP - Custom Import Fiscal Classification",
"summary": "Extra GRAP Tools to import data for"
"name": "GRAP - Custom Product Import - Fiscal Classification Module",
"summary": "Extra GRAP Tools to import product data for"
" Account Product Fiscal Classification",
"version": "16.0.1.0.0",
"category": "Tools",
"author": "GRAP",
"website": "https://github.com/grap/grap-odoo-import",
"license": "AGPL-3",
"depends": ["grap_custom_import_product", "account_product_fiscal_classification"],
"depends": [
"fermente_custom_import_product",
"account_product_fiscal_classification",
],
"auto_install": True,
"installable": True,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import custom_import_product_mixin
from . import product_template
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import _, fields, models
from odoo import _, models
from odoo.exceptions import ValidationError
from odoo.osv import expression


class ProductProduct(models.Model):
_inherit = "product.product"
class CustomImportProductMixin(models.AbstractModel):
_name = "custom.import.product.mixin"
_inherit = ["custom.import.product.mixin"]

grap_import_vat_amount = fields.Float(string="VAT Amount (For import)", store=False)

# pylint: disable=missing-return
def _custom_import_hook_vals(self, old_vals, new_vals):
super()._custom_import_hook_vals(old_vals, new_vals)
self._custom_import_handle_fiscal_classification_id(old_vals, new_vals)
return

def _custom_import_get_fiscal_classifications(self, vat_amount):
def _custom_import_fiscal_classification_domain(self, vat_amount):
domain = expression.OR(
[[("company_id", "=", self.env.company.id)], [("company_id", "=", False)]]
)
Expand All @@ -28,11 +27,7 @@ def _custom_import_get_fiscal_classifications(self, vat_amount):
else:
domain = expression.AND([domain, [("sale_tax_ids", "=", False)]])

return (
self.env["account.product.fiscal.classification"]
.search(domain)
.filtered(lambda x: len(x.sale_tax_ids) < 2)
)
return domain

def _custom_import_handle_fiscal_classification_id(self, old_vals, new_vals):
vat_amount = old_vals.get("grap_import_vat_amount")
Expand All @@ -43,11 +38,16 @@ def _custom_import_handle_fiscal_classification_id(self, old_vals, new_vals):
product_name=old_vals.get("name"),
)
)
classifications = self._custom_import_get_fiscal_classifications(vat_amount)
domain = self._custom_import_fiscal_classification_domain(vat_amount)

classifications = (
self.env["account.product.fiscal.classification"]
.search(domain)
.filtered(lambda x: len(x.sale_tax_ids) < 2)
)

if len(classifications) == 1:
new_vals["fiscal_classification_id"] = classifications.id
return

elif len(classifications) == 0:
raise ValidationError(
Expand All @@ -58,13 +58,24 @@ def _custom_import_handle_fiscal_classification_id(self, old_vals, new_vals):
vat_amount=vat_amount,
)
)

raise ValidationError(
_(
"Many Fiscal Classifications Found for the product %(product_name)s."
" Vat Amount %(vat_amount)s. Fiscal Classifications : %(classification_names)s",
product_name=old_vals.get("name"),
vat_amount=vat_amount,
classification_names=",".join(classifications.mapped("name")),
else:
raise ValidationError(
_(
"Many Fiscal Classifications Found for the product %(product_name)s."
" Vat Amount %(vat_amount)s."
" Fiscal Classifications : %(classification_names)s",
product_name=old_vals.get("name"),
vat_amount=vat_amount,
classification_names=",".join(classifications.mapped("name")),
)
)
)

# If Specific Vat Excl / VAT Incl field are set, we use it, depending of the
# the configuration of the fiscal classification
if (
all(classifications.mapped("sale_tax_ids.price_include"))
and "grap_import_list_price_vat_incl" in old_vals
):
new_vals["list_price"] = old_vals["grap_import_list_price_vat_incl"]
elif "grap_import_list_price_vat_excl" in old_vals:
new_vals["list_price"] = old_vals["grap_import_list_price_vat_excl"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class ProductTemplate(models.Model):
_inherit = "product.template"

grap_import_vat_amount = fields.Float(string="VAT Amount (For import)", store=False)

grap_import_list_price_vat_excl = fields.Float(
string="Sale Price Vat Excl (For import)", store=False
)

grap_import_list_price_vat_incl = fields.Float(
string="Sale Price Vat Incl (For import)", store=False
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name,uom_id,categ_id,grap_import_vat_amount,grap_import_list_price_vat_excl,grap_import_list_price_vat_incl
Product 1,Units,All / Saleable,0.20,1,1.21
Product 2,Units,All / Saleable,0.20,0.99,1.20
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.tests import tagged

from odoo.addons.fermente_custom_import_product.tests.test_module import (
TestModuleProduct,
)


@tagged("post_install", "-at_install")
class TestModuleProductSupplierinfoQtyMultiplier(TestModuleProduct):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.classification_20 = cls.env.ref(
"account_product_fiscal_classification.fiscal_classification_A_company_1"
)
cls.tax_20 = cls.env.ref(
"account_product_fiscal_classification.account_tax_sale_20_company_1"
)

def _test_import_product_account_product_fiscal_classification(
self, model, vat_included
):
products, messages = self._test_import_file(
"fermente_custom_import_account_product_fiscal_classification",
model,
"product.csv",
folder="product",
)
self.assertFalse(messages)
self.assertEqual(len(products), 2)

product_1 = products.filtered(lambda x: x.name == "Product 1")
self.assertEqual(product_1.fiscal_classification_id, self.classification_20)

product_2 = products.filtered(lambda x: x.name == "Product 2")
self.assertEqual(product_2.fiscal_classification_id, self.classification_20)

if vat_included:
self.assertEqual(product_1.list_price, 1.21)
self.assertEqual(product_2.list_price, 1.20)
else:
self.assertEqual(product_1.list_price, 1.00)
self.assertEqual(product_2.list_price, 0.99)

def test_01_import_product_account_product_fiscal_classification_product_vat_excl(
self,
):
self.tax_20.price_include = False
self._test_import_product_account_product_fiscal_classification(
"product.product", False
)

def test_02_import_product_account_product_fiscal_classification_product_vat_incl(
self,
):
self.tax_20.price_include = True
self._test_import_product_account_product_fiscal_classification(
"product.product", True
)

def test_11_import_product_account_product_fiscal_classification_template_vat_excl(
self,
):
self.tax_20.price_include = False
self._test_import_product_account_product_fiscal_classification(
"product.template", False
)

def test_12_import_product_account_product_fiscal_classification_template_vat_incl(
self,
):
self.tax_20.price_include = True
self._test_import_product_account_product_fiscal_classification(
"product.template", True
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ GRAP - Custom Import Base Module
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-grap%2Fgrap--odoo--import-lightgray.png?logo=github
:target: https://github.com/grap/grap-odoo-import/tree/16.0/grap_custom_import_base
:target: https://github.com/grap/grap-odoo-import/tree/16.0/fermente_custom_import_base
:alt: grap/grap-odoo-import

|badge1| |badge2| |badge3|
Expand All @@ -41,7 +41,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/grap/grap-odoo-import/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/grap/grap-odoo-import/issues/new?body=module:%20grap_custom_import_base%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/grap/grap-odoo-import/issues/new?body=module:%20fermente_custom_import_base%0Aversion:%2016.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 All @@ -61,6 +61,6 @@ Contributors
Maintainers
~~~~~~~~~~~

This module is part of the `grap/grap-odoo-import <https://github.com/grap/grap-odoo-import/tree/16.0/grap_custom_import_base>`_ project on GitHub.
This module is part of the `grap/grap-odoo-import <https://github.com/grap/grap-odoo-import/tree/16.0/fermente_custom_import_base>`_ project on GitHub.

You are welcome to contribute.
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import custom_import_mixin
from . import custom_import_partner_mixin
from . import res_partner
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def _custom_import_hook_vals(self, old_vals, new_vals):
)
return new_vals

def _custom_import_hook_check(self, vals_list):
self._custom_import_check_duplicates_new_vals(vals_list)

def _custom_import_check_duplicates_new_vals(self, vals_list):
for field in self._custom_import_prevent_duplicate_fields():
duplicates = []
Expand Down Expand Up @@ -72,11 +75,19 @@ def _custom_import_get_or_create(

# Overload Section
def _load_records_create(self, vals_list):
# This function is called in many places in odoo Core
# to create records, specially when loading
# 'demo' or 'data' from xml files.
# We only want to alter data in a 'import' process.
if not self.env.context.get("import_file"):
return super()._load_records_create(vals_list)

new_vals_list = []
for vals in vals_list:
new_vals = vals.copy()
self._custom_import_hook_vals(vals, new_vals)
new_vals_list.append(new_vals)
# TODO, move this check in another part
self._custom_import_check_duplicates_new_vals(new_vals_list)

self._custom_import_hook_check(new_vals_list)

return super()._load_records_create(new_vals_list)
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging

from odoo import models

logger = logging.getLogger(__name__)


class ResPartner(models.Model):
_name = "res.partner"
_inherit = ["res.partner", "custom.import.mixin"]
class CustomImportPartnerMixin(models.AbstractModel):
_name = "custom.import.partner.mixin"
_description = "Abstract model to import partner (customer and supplier)"
_inherit = ["custom.import.mixin"]

def _custom_import_prevent_duplicate_fields(self):
res = super()._custom_import_prevent_duplicate_fields()
Expand Down
14 changes: 14 additions & 0 deletions fermente_custom_import_base/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging

from odoo import models

logger = logging.getLogger(__name__)


class ResPartner(models.Model):
_name = "res.partner"
_inherit = ["res.partner", "custom.import.partner.mixin"]
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ It provides generic tools for that purpose, and improve imports for some models.

* ``res.partner``:

* Prevent to create duplicates regarding ``name`` and ``vat`` fields.
* Prevent to create duplicates regarding ``name`` and ``vat`` fields.

TO FINISH
2 changes: 2 additions & 0 deletions fermente_custom_import_base/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import test_module
from . import test_module_partner
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name,email,phone,mobile,website,street,street2,zip,city,country_id,vat
Azure Interior,,,,,,,,,,
Loading
Loading