Files
intrastat-extrastat/product_harmonized_system/models/hs_code.py
BenjaHe 4b0275018c [13.0] [MIG] product harmonized system (#80)
* Large code re-engineering following the Akretion-Noviat code sprint on intrastat

This code has been written both by Luc de Meyer and myself.

* hs_code display_name fix

* major update intrastat V3 modules

* Add product_origin_country_id on declaration/computation lines

Copy incoterms and destination country from SO to invoice when invoicing from SO
We need weight even when supplementary units is used
Small cleanups and enhancements

* Add support for accessory costs

Add default values for intrastat transaction on company
Code cleanup

* this week's ci errors

* Update README.rst

Rename variables

* Port intrastat_base to v10

Set 2 other modules to uninstallable
Update README.rst: switch to new intrastat project

* Port product_harmonized_system to v10

* Fix warning on display_name

Special thanks to Pedro and Holger for finding the solution for display_name
Fix demo data

* [MIG] product_harmonized_system: Migration to 11.0

* [FIX] product_harmonized_system: fix get_hs_code_recurively

* [IMP] *: removed utf-8 headers, changed icon and site

* company model test, country model test as in v8
* png logo instead of svg, removed Python 2 utf-8 headers

* [UPD] Update product_harmonized_system.pot

* Add new module product_harmonized_system_delivery (hide native hs_code field)

Finalize port to v11

* [FIX+IMP] intrastat_*: Several things:

* Add readonly on some fields when state of declaration is done
* Division by zero in computation of accessory costs
* Add FR translation
* Fix strings
* Minor code updates

* [MIG] intrastat_product: Migration to 11.0

* Small fixes in intrastat_base
* account_tax_template

* [ADD] icon.png

* [UPD] Update product_harmonized_system.pot

* Prepare v12 branch

* [MIG] Migrate all modules from v11 to v12

* flake8

* [UPD] Update product_harmonized_system.pot

* Update translation files

Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: intrastat-extrastat-12.0/intrastat-extrastat-12.0-product_harmonized_system
Translate-URL: https://translation.odoo-community.org/projects/intrastat-extrastat-12-0/intrastat-extrastat-12-0-product_harmonized_system/

* [FIX] product_harmized_system DESCRIPTION.rst

* [UPD] README.rst

* [UPD] README.rst

* Added translation using Weblate (Spanish)

* Translated using Weblate (Spanish)

Currently translated at 50.0% (18 of 36 strings)

Translation: intrastat-extrastat-12.0/intrastat-extrastat-12.0-product_harmonized_system
Translate-URL: https://translation.odoo-community.org/projects/intrastat-extrastat-12-0/intrastat-extrastat-12-0-product_harmonized_system/es/

* [MIG] product_harmonized_system : Migration to 13.0

* [IMP] product_harmonized_system: black, isort
2020-11-19 17:46:48 +01:00

104 lines
3.4 KiB
Python

# Copyright 2011-2016 Akretion France (http://www.akretion.com)
# Copyright 2009-2016 Noviat (http://www.noviat.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# @author Luc de Meyer <info@noviat.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class HSCode(models.Model):
_name = "hs.code"
_description = "H.S. Code"
_order = "local_code"
_rec_name = "local_code"
hs_code = fields.Char(
string="H.S. Code",
compute="_compute_hs_code",
readonly=True,
help="Harmonized System code (6 digits). Full list is "
"available from the World Customs Organisation, see "
"http://www.wcoomd.org",
)
description = fields.Char(
translate=True, help="Short text description of the H.S. category"
)
local_code = fields.Char(
required=True,
help="Code used for the national Import/Export declaration. "
"The national code starts with the 6 digits of the H.S. and often "
"has a few additional digits to extend the H.S. code.",
)
active = fields.Boolean(default=True)
company_id = fields.Many2one(
"res.company",
string="Company",
readonly=True,
required=True,
default=lambda self: self.env["res.company"]._company_default_get(),
)
product_categ_ids = fields.One2many(
comodel_name="product.category",
inverse_name="hs_code_id",
string="Product Categories",
readonly=True,
)
product_tmpl_ids = fields.One2many(
comodel_name="product.template",
inverse_name="hs_code_id",
string="Products",
readonly=True,
)
product_categ_count = fields.Integer(compute="_compute_product_categ_count")
product_tmpl_count = fields.Integer(compute="_compute_product_tmpl_count")
@api.depends("local_code")
def _compute_hs_code(self):
for this in self:
this.hs_code = this.local_code and this.local_code[:6]
@api.depends("product_categ_ids")
def _compute_product_categ_count(self):
# hs_code_id on product.category is company_dependent=True
# so we can't use a read_group()
for code in self:
code.product_categ_count = len(code.product_categ_ids)
@api.depends("product_tmpl_ids")
def _compute_product_tmpl_count(self):
# hs_code_id on product.template is company_dependent=True
# so we can't use a read_group()
for code in self:
code.product_tmpl_count = len(code.product_tmpl_ids)
@api.depends("local_code", "description")
def name_get(self):
res = []
for this in self:
name = this.local_code
if this.description:
name += " " + this.description
name = len(name) > 55 and name[:55] + "..." or name
res.append((this.id, name))
return res
_sql_constraints = [
(
"local_code_company_uniq",
"unique(local_code, company_id)",
"This code already exists for this company !",
)
]
@api.model
def create(self, vals):
if vals.get("local_code"):
vals["local_code"] = vals["local_code"].replace(" ", "")
return super(HSCode, self).create(vals)
def write(self, vals):
if vals.get("local_code"):
vals["local_code"] = vals["local_code"].replace(" ", "")
return super(HSCode, self).write(vals)