Skip to content

Commit

Permalink
[16.0][ADD] report_qweb_decimal_precision (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuhehe1995 authored Feb 21, 2024
1 parent 6f1bf58 commit e262f3c
Show file tree
Hide file tree
Showing 20 changed files with 994 additions and 0 deletions.
124 changes: 124 additions & 0 deletions report_qweb_decimal_precision/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
=============================
Report QWeb Decimal Precision
=============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:57c9255697870b6f440d3b2d73a09d237efa009ab54b93ddb2545366507dfa5f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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%2Freporting--engine-lightgray.png?logo=github
:target: https://github.com/OCA/reporting-engine/tree/16.0/report_qweb_decimal_precision
:alt: OCA/reporting-engine
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/reporting-engine-16-0/reporting-engine-16-0-report_qweb_decimal_precision
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/reporting-engine&target_branch=16.0
:alt: Try me on Runboat

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

This module allows administrators to define the decimal precision of
float fields for QWeb report presentation.

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

Odoo's QWeb reports display values of float fields based on the decimal
accuracy settings, which are global and sometimes bring inconveniences.

For example:

- You have some products which require a fine precision with inventory
management (e.g. liquid, powder, etc.) and you set 'Product Unit of
Measure' to 4, but you don't want to show '2.0000 Units' on your
quotation to sell assembled products (you may just want to show '2
Units').
- You purchase some raw materials in bulk in USD whose unit price comes
down to the 4th decimal place and you set 'Product Price' to this
level or precision, but you don't want to show the unit price of a
product as '120,000.0000' on your JPY quotation (you would just want
to show '120,000').

This module is designed to address these inconveniences.

Configuration
=============

Go to *Settings > Technical > Reporting > Decimal Precision QWeb*, and
create records according to your needs.

For each record:

- choose a model and a float-type field (required)
- set UoM and UoM Field, or Currency and Currency Field (optional)
- set Company (optional)
- set Digits (required)

Usage
=====

Print a QWeb report (quotation, invoice, purchase order, etc.), and the
value presentation for fields like line quantity and price unit are
adjusted according to the Decimal Precision QWeb configuration.

Note that among matching config records, the one with the strictest
condition will be adopted.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/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/OCA/reporting-engine/issues/new?body=module:%20report_qweb_decimal_precision%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.

Credits
=======

Authors
-------

* Quartile Limited

Contributors
------------

- `Quartile Limited <https://www.quartile.co>`__:

- Yoshi Tashiro
- Aung Ko Ko Lin

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/reporting-engine <https://github.com/OCA/reporting-engine/tree/16.0/report_qweb_decimal_precision>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions report_qweb_decimal_precision/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions report_qweb_decimal_precision/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2024 Quartile Limited (https://www.quartile.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Report QWeb Decimal Precision",
"version": "16.0.1.0.0",
"category": "Technical Settings",
"license": "AGPL-3",
"author": "Quartile Limited, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/reporting-engine",
"depends": ["uom"],
"data": [
"security/ir.model.access.csv",
"security/decimal_precision_qweb_security.xml",
"views/decimal_precision_qweb_views.xml",
],
"installable": True,
}
124 changes: 124 additions & 0 deletions report_qweb_decimal_precision/i18n/ja.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * report_qweb_decimal_precision
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-02-19 08:28+0000\n"
"PO-Revision-Date: 2024-02-19 08:28+0000\n"
"Last-Translator: \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: report_qweb_decimal_precision
#: model:ir.model.fields,field_description:report_qweb_decimal_precision.field_decimal_precision_qweb__company_id
msgid "Company"
msgstr "会社"

#. module: report_qweb_decimal_precision
#: model:ir.model.fields,field_description:report_qweb_decimal_precision.field_decimal_precision_qweb__create_uid
msgid "Created by"
msgstr "作成者"

#. module: report_qweb_decimal_precision
#: model:ir.model.fields,field_description:report_qweb_decimal_precision.field_decimal_precision_qweb__create_date
msgid "Created on"
msgstr "作成日"

#. module: report_qweb_decimal_precision
#: model:ir.model.fields,field_description:report_qweb_decimal_precision.field_decimal_precision_qweb__currency_id
msgid "Currency"
msgstr "通貨"

#. module: report_qweb_decimal_precision
#: model:ir.model.fields,field_description:report_qweb_decimal_precision.field_decimal_precision_qweb__currency_field_id
msgid "Currency Field"
msgstr "通貨項目"

#. module: report_qweb_decimal_precision
#: model:ir.actions.act_window,name:report_qweb_decimal_precision.action_decimal_precision_qweb_view
#: model:ir.model,name:report_qweb_decimal_precision.model_decimal_precision_qweb
#: model:ir.ui.menu,name:report_qweb_decimal_precision.menu_decimal_precision_qweb
msgid "Decimal Precision QWeb"
msgstr "QWeb小数点精度"

#. module: report_qweb_decimal_precision
#: model:ir.model.fields,field_description:report_qweb_decimal_precision.field_decimal_precision_qweb__digits
msgid "Digits"
msgstr "桁数"

#. module: report_qweb_decimal_precision
#: model:ir.model.fields,field_description:report_qweb_decimal_precision.field_decimal_precision_qweb__display_name
msgid "Display Name"
msgstr "表示名"

#. module: report_qweb_decimal_precision
#: model:ir.model.fields,field_description:report_qweb_decimal_precision.field_decimal_precision_qweb__field_id
msgid "Field"
msgstr "項目"

#. module: report_qweb_decimal_precision
#: model:ir.model.fields,field_description:report_qweb_decimal_precision.field_decimal_precision_qweb__field_name
msgid "Field Name"
msgstr "項目名"

#. module: report_qweb_decimal_precision
#: model_terms:ir.ui.view,arch_db:report_qweb_decimal_precision.view_decimal_precision_qweb_searh
msgid "Group By"
msgstr "グループ化"

#. module: report_qweb_decimal_precision
#: model:ir.model.fields,field_description:report_qweb_decimal_precision.field_decimal_precision_qweb__id
msgid "ID"
msgstr "ID"

#. module: report_qweb_decimal_precision
#: model:ir.model.fields,field_description:report_qweb_decimal_precision.field_decimal_precision_qweb____last_update
msgid "Last Modified on"
msgstr "最終更新日"

#. module: report_qweb_decimal_precision
#: model:ir.model.fields,field_description:report_qweb_decimal_precision.field_decimal_precision_qweb__write_uid
msgid "Last Updated by"
msgstr "最終更新者"

#. module: report_qweb_decimal_precision
#: model:ir.model.fields,field_description:report_qweb_decimal_precision.field_decimal_precision_qweb__write_date
msgid "Last Updated on"
msgstr "最終更新日"

#. module: report_qweb_decimal_precision
#: model:ir.model.fields,field_description:report_qweb_decimal_precision.field_decimal_precision_qweb__res_model_id
#: model_terms:ir.ui.view,arch_db:report_qweb_decimal_precision.view_decimal_precision_qweb_searh
msgid "Model"
msgstr "モデル"

#. module: report_qweb_decimal_precision
#: model:ir.model.fields,field_description:report_qweb_decimal_precision.field_decimal_precision_qweb__res_model_name
msgid "Model Name"
msgstr "モデル名"

#. module: report_qweb_decimal_precision
#: model_terms:ir.ui.view,arch_db:report_qweb_decimal_precision.view_decimal_precision_qweb_searh
msgid "Precision QWeb Search"
msgstr "QWeb精度検索"

#. module: report_qweb_decimal_precision
#: model:ir.model,name:report_qweb_decimal_precision.model_ir_qweb_field_float
msgid "Qweb Field Float"
msgstr "QWeb浮動小数点項目"

#. module: report_qweb_decimal_precision
#: model:ir.model.fields,field_description:report_qweb_decimal_precision.field_decimal_precision_qweb__uom_id
msgid "UoM"
msgstr "計量単位"

#. module: report_qweb_decimal_precision
#: model:ir.model.fields,field_description:report_qweb_decimal_precision.field_decimal_precision_qweb__uom_field_id
msgid "UoM Field"
msgstr "計量単位項目"
2 changes: 2 additions & 0 deletions report_qweb_decimal_precision/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import decimal_precision_qweb
from . import ir_qweb_fields
59 changes: 59 additions & 0 deletions report_qweb_decimal_precision/models/decimal_precision_qweb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2024 Quartile Limited (https://www.quartile.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class DecimalPrecisioQweb(models.Model):
_name = "decimal.precision.qweb"
_description = "Decimal Precision QWeb"
_order = "res_model_id, field_id"

res_model_id = fields.Many2one(
"ir.model", string="Model", ondelete="cascade", required=True
)
res_model_name = fields.Char("Model Name", related="res_model_id.model", store=True)
field_id = fields.Many2one(
"ir.model.fields",
domain="[('model_id', '=', res_model_id), ('ttype', '=', 'float')]",
string="Field",
ondelete="cascade",
required=True,
)
field_name = fields.Char("Field Name", related="field_id.name", store=True)
uom_id = fields.Many2one("uom.uom", string="UoM", ondelete="cascade")
uom_field_id = fields.Many2one(
"ir.model.fields",
domain="[('model_id', '=', res_model_id), ('relation', '=', 'uom.uom')]",
string="UoM Field",
ondelete="cascade",
)
currency_id = fields.Many2one("res.currency", string="Currency", ondelete="cascade")
currency_field_id = fields.Many2one(
"ir.model.fields",
domain="[('model_id', '=', res_model_id), ('relation', '=', 'res.currency')]",
string="Currency Field",
ondelete="cascade",
)
digits = fields.Integer(required=True)
company_id = fields.Many2one("res.company", string="Company")

def _get_score(self, record):
self.ensure_one()
score = 1
if self.company_id:
if record.company_id == self.company_id:
score += 1
else:
return -1
if self.uom_id:
if record[self.uom_field_id.sudo().name] == self.uom_id:
score += 1
else:
return -1
if self.currency_id:
if record[self.currency_field_id.sudo().name] == self.currency_id:
score += 1
else:
return -1
return score
21 changes: 21 additions & 0 deletions report_qweb_decimal_precision/models/ir_qweb_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 Quartile Limited (https://www.quartile.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models


class FloatConverter(models.AbstractModel):
_inherit = "ir.qweb.field.float"

@api.model
def record_to_html(self, record, field_name, options):
if "precision" not in options and "decimal_precision" not in options:
dp_qweb_recs = self.env["decimal.precision.qweb"].search(
[("res_model_name", "=", record._name), ("field_name", "=", field_name)]
)
precision_rec = max(
dp_qweb_recs, default=None, key=lambda r: r._get_score(record)
)
if precision_rec:
options = dict(options, precision=precision_rec.digits)
return super().record_to_html(record, field_name, options)
9 changes: 9 additions & 0 deletions report_qweb_decimal_precision/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Go to *Settings > Technical > Reporting > Decimal Precision QWeb*, and create records
according to your needs.

For each record:

* choose a model and a float-type field (required)
* set UoM and UoM Field, or Currency and Currency Field (optional)
* set Company (optional)
* set Digits (required)
15 changes: 15 additions & 0 deletions report_qweb_decimal_precision/readme/CONTEXT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Odoo's QWeb reports display values of float fields based on the decimal accuracy
settings, which are global and sometimes bring inconveniences.

For example:

* You have some products which require a fine precision with inventory management (e.g.
liquid, powder, etc.) and you set 'Product Unit of Measure' to 4, but you don't want
to show '2.0000 Units' on your quotation to sell assembled products (you may just want
to show '2 Units').
* You purchase some raw materials in bulk in USD whose unit price comes down to the 4th
decimal place and you set 'Product Price' to this level or precision, but you don't
want to show the unit price of a product as '120,000.0000' on your JPY quotation (you
would just want to show '120,000').

This module is designed to address these inconveniences.
3 changes: 3 additions & 0 deletions report_qweb_decimal_precision/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* [Quartile Limited](https://www.quartile.co):
* Yoshi Tashiro
* Aung Ko Ko Lin
2 changes: 2 additions & 0 deletions report_qweb_decimal_precision/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module allows administrators to define the decimal precision of float fields for
QWeb report presentation.
6 changes: 6 additions & 0 deletions report_qweb_decimal_precision/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Print a QWeb report (quotation, invoice, purchase order, etc.), and the value
presentation for fields like line quantity and price unit are adjusted according to the
Decimal Precision QWeb configuration.

Note that among matching config records, the one with the strictest condition will be
adopted.
Loading

0 comments on commit e262f3c

Please sign in to comment.