[130] nfu_ecommerce: advanced credit handling

* [IMP] apply pre-commits and small fixes

* [imp] nfu_ecommerce: add avoid_depts

* [IMP] nfu_ecommerce: use warning level in checkout

* [IMP] nfu_ecommerce: add translation

---------

Co-authored-by: Niels Göttsch <ng@ife.de>
This commit is contained in:
madmooose 2025-07-29 13:10:04 +02:00 committed by GitHub
parent 1c89538b2d
commit fee5016550
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 196 additions and 69 deletions

View file

@ -22,10 +22,17 @@ NFU eCommerce
|badge1| |badge2| |badge3|
This module adds a maximum order quantity field to Website Sale Orders. It also adds
an ordered qantitiy field to store the original ordered quantity in case a manager
adjustes the uom quantitiy. In webshop checkout it adds the customer balance to before
and after the current order.
This module adds
- a maximum order quantity field to Website Sale Orders
- ordered qantitiy field to store the original ordered quantity in case a manager
adjustes the uom quantitiy
In webshop checkout it adds
- the customer balance to before and after the current order
- a configuration to warn when credit is low
- a possibility to only use credit for ordering
**Table of contents**
@ -44,6 +51,7 @@ Changelog
:1.3.0: Adapt new Open Packages format and add indicators
:1.3.1: Remove Max Qty from first page
:1.3.2: Add decimal to ribbon
:1.4.0: Add credit warning and avoid debts option
Bug Tracker
===========

View file

@ -4,7 +4,7 @@
"author": "BAKEUP",
"website": "https://www.bakeup.org",
"category": "website",
"version": "16.0.1.3.2",
"version": "16.0.1.4.0",
"depends": [
"sale_product_configurator",
"website_sale",
@ -12,11 +12,14 @@
"website_decimal_quantity",
"nfu_product_bnn_attributes",
],
"data": ["views/product_template_views.xml", "views/templates.xml"],
"data": [
"views/res_config_settings_views.xml",
"views/product_template_views.xml",
"views/templates.xml",
],
"assets": {
"web.assets_frontend": [
"nfu_ecommerce/static/src/js/website_sale.js",
"nfu_ecommerce/static/src/js/sale_product_configurator.js",
"nfu_ecommerce/static/src/js/*.js",
]
},
"license": "LGPL-3",

View file

@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-10-04 19:54+0000\n"
"PO-Revision-Date: 2024-10-04 19:54+0000\n"
"POT-Creation-Date: 2025-07-24 18:34+0000\n"
"PO-Revision-Date: 2025-07-24 18:34+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
@ -22,6 +22,7 @@ msgstr "<span>Max Menge</span>"
#. module: nfu_ecommerce
#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.cart_lines_packaging
#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.product_max_quantity_config
msgid "Add one"
msgstr "Einen hinzufügen"
@ -31,6 +32,12 @@ msgstr "Einen hinzufügen"
msgid "All Products"
msgstr "Alle Produkte"
#. module: nfu_ecommerce
#: model:ir.model.fields,field_description:nfu_ecommerce.field_res_config_settings__website_avoid_depts
#: model:ir.model.fields,field_description:nfu_ecommerce.field_website__avoid_depts
msgid "Avoid depths"
msgstr "Schulden verhindern"
#. module: nfu_ecommerce
#: model:ir.model.fields,field_description:nfu_ecommerce.field_sale_order__balance
msgid "Balance"
@ -42,10 +49,22 @@ msgid "Balance:"
msgstr "Aktuelles Guthaben:"
#. module: nfu_ecommerce
#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.cart_lines_packaging
#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.cart_summary_packaging
msgid "Max Ordered Quantity:"
msgstr "Max Menge"
#: model:ir.model,name:nfu_ecommerce.model_res_config_settings
msgid "Config Settings"
msgstr "Konfigurationseinstellungen"
#. module: nfu_ecommerce
#: model:ir.model.fields,field_description:nfu_ecommerce.field_res_config_settings__website_credit_warning_level
#: model:ir.model.fields,field_description:nfu_ecommerce.field_website__credit_warning_level
#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.res_config_settings_view_form
msgid "Credit Warning"
msgstr "Guthabenwarnung"
#. module: nfu_ecommerce
#: model:ir.model.fields,field_description:nfu_ecommerce.field_product_product__is_published
#: model:ir.model.fields,field_description:nfu_ecommerce.field_product_template__is_published
msgid "Is Published"
msgstr "Ist veröffentlicht"
#. module: nfu_ecommerce
#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.cart_summary_packaging
@ -57,17 +76,6 @@ msgstr "Max Menge:"
msgid "New balance:"
msgstr "Neues Guthaben:"
#. module: nfu_ecommerce
#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.cart_lines_packaging
msgid "No open package available"
msgstr "Keine offenen Gebinde"
#. module: nfu_ecommerce
#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.cart_lines_packaging
#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.cart_summary_packaging
msgid "Open Package:"
msgstr "Offenes Gebinde:"
#. module: nfu_ecommerce
#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.o_wsale_offcanvas
#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.products_open_packaging
@ -75,9 +83,14 @@ msgid "Open Packagings"
msgstr "Offene Gebinde"
#. module: nfu_ecommerce
#: model:ir.model.fields,field_description:nfu_ecommerce.field_sale_order_line__open_qty
msgid "Open Qty"
msgstr "Offene Menge"
#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.cart_lines_packaging
msgid "Packaging Size:"
msgstr "Verpackungsgröße:"
#. module: nfu_ecommerce
#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.res_config_settings_view_form
msgid "Prevent Customers from Ordering more than their Credit."
msgstr "Verhindere das Kunden mehr Kaufen als mit ihrem Guthaben möglich"
#. module: nfu_ecommerce
#: model:ir.model,name:nfu_ecommerce.model_product_template
@ -91,19 +104,20 @@ msgstr "Veröffentlichen"
#. module: nfu_ecommerce
#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.cart_lines_packaging
#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.product_max_quantity_config
msgid "Remove one"
msgstr "Eins entfernen"
#. module: nfu_ecommerce
#: model:ir.model,name:nfu_ecommerce.model_sale_order_batch_product
msgid "Sale Order Batch Product"
msgstr ""
#. module: nfu_ecommerce
#: model:ir.model,name:nfu_ecommerce.model_sale_order
msgid "Sales Order"
msgstr "Verkaufsauftrag"
#. module: nfu_ecommerce
#: model:ir.model,name:nfu_ecommerce.model_sale_order_line
msgid "Sales Order Line"
msgstr "Verkaufsauftragszeile"
#. module: nfu_ecommerce
#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.product_template_tree_view
msgid "Unpublish on Website"
@ -118,3 +132,25 @@ msgstr "Zukünftiges Guthaben"
#: model_terms:ir.ui.view,arch_db:nfu_ecommerce.cart_lines_packaging
msgid "Warning"
msgstr "Warnung"
#. module: nfu_ecommerce
#: model:ir.model,name:nfu_ecommerce.model_website
msgid "Website"
msgstr ""
#. module: nfu_ecommerce
#: model:ir.model.fields,help:nfu_ecommerce.field_res_config_settings__website_credit_warning_level
#: model:ir.model.fields,help:nfu_ecommerce.field_website__credit_warning_level
msgid ""
"When the credit of a customer is lower than the warning level the credit is "
"shown in red on the website."
msgstr ""
"Wenn das Guthaben niedriger ist als die Guthabenswarnung wird das Guthaben "
"auf der website in rot angezeigt."
#. module: nfu_ecommerce
#. odoo-python
#: code:addons/nfu_ecommerce/models/sale_order.py:0
#, python-format
msgid "You don't have enough credit."
msgstr "Du hast nicht genug Guthaben."

View file

@ -1,3 +1,5 @@
from . import product_template
from . import res_config_settings
from . import sale_order
from . import sale_order_batch_product
from . import website

View file

@ -0,0 +1,12 @@
from odoo import fields, models
class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"
website_credit_warning_level = fields.Monetary(
related="website_id.credit_warning_level", readonly=False
)
website_avoid_depts = fields.Boolean(
related="website_id.avoid_depts", readonly=False
)

View file

@ -1,4 +1,5 @@
from odoo import api, fields, models
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
class SaleOrder(models.Model):
@ -18,6 +19,14 @@ class SaleOrder(models.Model):
order.amount_total / order.currency_rate
)
@api.constrains("amount_total")
def _check_amount_total(self):
for order in self:
if order.state != "draft" or not order.website_id:
continue
if order.website_id.avoid_depts and order.updated_balance < 0:
raise ValidationError(_("You don't have enough credit."))
def _prepare_order_line_values(
self,
product_id,

View file

@ -0,0 +1,12 @@
from odoo import fields, models
class Website(models.Model):
_inherit = "website"
credit_warning_level = fields.Monetary(
string="Credit Warning",
readonly=False,
help="When the credit of a customer is lower than the warning level the credit is shown in red on the website.",
)
avoid_depts = fields.Boolean(string="Avoid depths")

View file

@ -1,4 +1,11 @@
This module adds a maximum order quantity field to Website Sale Orders. It also adds
an ordered qantitiy field to store the original ordered quantity in case a manager
adjustes the uom quantitiy. In webshop checkout it adds the customer balance to before
and after the current order.
This module adds
- a maximum order quantity field to Website Sale Orders
- ordered qantitiy field to store the original ordered quantity in case a manager
adjustes the uom quantitiy
In webshop checkout it adds
- the customer balance to before and after the current order
- a configuration to warn when credit is low
- a possibility to only use credit for ordering

View file

@ -7,3 +7,4 @@
:1.3.0: Adapt new Open Packages format and add indicators
:1.3.1: Remove Max Qty from first page
:1.3.2: Add decimal to ribbon
:1.4.0: Add credit warning and avoid debts option

View file

@ -370,10 +370,18 @@ ul.auto-toc {
!! source digest: sha256:4dfaea54e4d01502b433eb5c0dcca409a5fbe2c3f175e29382a19230343183c9
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/bruecksen/nfu/tree/16.0/nfu_ecommerce"><img alt="bruecksen/nfu" src="https://img.shields.io/badge/github-bruecksen%2Fnfu-lightgray.png?logo=github" /></a></p>
<p>This module adds a maximum order quantity field to Website Sale Orders. It also adds
an ordered qantitiy field to store the original ordered quantity in case a manager
adjustes the uom quantitiy. In webshop checkout it adds the customer balance to before
and after the current order.</p>
<p>This module adds</p>
<ul class="simple">
<li>a maximum order quantity field to Website Sale Orders</li>
<li>ordered qantitiy field to store the original ordered quantity in case a manager
adjustes the uom quantitiy</li>
</ul>
<p>In webshop checkout it adds</p>
<ul class="simple">
<li>the customer balance to before and after the current order</li>
<li>a configuration to warn when credit is low</li>
<li>a possibility to only use credit for ordering</li>
</ul>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
@ -411,6 +419,8 @@ and after the current order.</p>
</tr>
<tr class="field"><th class="field-name">1.3.2:</th><td class="field-body">Add decimal to ribbon</td>
</tr>
<tr class="field"><th class="field-name">1.4.0:</th><td class="field-body">Add credit warning and avoid debts option</td>
</tr>
</tbody>
</table>
</div>

View file

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit.nfu.eccommerce</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="website_sale.res_config_settings_view_form"/>
<field name="arch" type="xml">
<div id="website_shop_checkout" position="inside">
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_right_pane">
<div class="content-group">
<div class="row mt16">
<label
class="o_light_label col-lg-3"
string="Credit Warning"
for="website_credit_warning_level"
/>
<field name="website_credit_warning_level"/>
</div>
</div>
</div>
</div>
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="website_avoid_depts"/>
</div>
<div class="o_setting_right_pane">
<label for="website_avoid_depts"/>
<div class="text-muted">
Prevent Customers from Ordering more than their Credit.
</div>
</div>
</div>
</div>
</field>
</record>
</odoo>

View file

@ -264,7 +264,7 @@
<td class="text-xl-end border-0">
<span
t-field="website_sale_order.balance"
class="monetary_field"
t-att-class="'monetary_field' + (' text-danger' if website_sale_order.balance &lt; website.credit_warning_level else '')"
style="white-space: nowrap;"
t-options="{'widget': 'monetary', 'display_currency': website_sale_order.currency_id}"
/>
@ -275,22 +275,12 @@
<tr id="updated_balance">
<td class="text-end border-0">New balance:</td>
<td class="text-xl-end border-0">
<t t-if="website_sale_order.updated_balance &lt; 0">
<span
t-field="website_sale_order.updated_balance"
class="monetary_field text-danger"
style="white-space: nowrap;"
t-options="{'widget': 'monetary', 'display_currency': website_sale_order.currency_id}"
/>
</t>
<t t-else="">
<span
t-field="website_sale_order.updated_balance"
t-att-class="monetary_field"
style="white-space: nowrap;"
t-options="{'widget': 'monetary', 'display_currency': website_sale_order.currency_id}"
/>
</t>
<span
t-field="website_sale_order.updated_balance"
t-att-class="'monetary_field' + (' text-danger' if website_sale_order.updated_balance &lt; website.credit_warning_level else '')"
style="white-space: nowrap;"
t-options="{'widget': 'monetary', 'display_currency': website_sale_order.currency_id}"
/>
</td>
</tr>
</xpath>

View file

@ -16,9 +16,9 @@ Website Decimal Quantity
.. |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-bruecksen%2Fife_nfu-lightgray.png?logo=github
:target: https://github.com/bruecksen/ife_nfu/tree/16.0/website_decimal_quantity
:alt: bruecksen/ife_nfu
.. |badge3| image:: https://img.shields.io/badge/github-bruecksen%2Fnfu-lightgray.png?logo=github
:target: https://github.com/bruecksen/nfu/tree/16.0/website_decimal_quantity
:alt: bruecksen/nfu
|badge1| |badge2| |badge3|
@ -39,10 +39,10 @@ Changelog
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/bruecksen/ife_nfu/issues>`_.
Bugs are tracked on `GitHub Issues <https://github.com/bruecksen/nfu/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/bruecksen/ife_nfu/issues/new?body=module:%20website_decimal_quantity%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/bruecksen/nfu/issues/new?body=module:%20website_decimal_quantity%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.
@ -64,6 +64,6 @@ Contributors
Maintainers
~~~~~~~~~~~
This module is part of the `bruecksen/ife_nfu <https://github.com/bruecksen/ife_nfu/tree/16.0/website_decimal_quantity>`_ project on GitHub.
This module is part of the `bruecksen/nfu <https://github.com/bruecksen/nfu/tree/16.0/website_decimal_quantity>`_ project on GitHub.
You are welcome to contribute.

View file

@ -89,12 +89,12 @@ class SaleOrder(models.Model):
set_qty = 0
quantity = 0
if set_qty:
quantity = set_qty
quantity = int(set_qty)
elif add_qty is not None:
if order_line:
quantity = order_line.product_uom_qty + (add_qty or 0)
quantity = order_line.product_uom_qty + (int(add_qty) or 0)
else:
quantity = add_qty or 0
quantity = int(add_qty) or 0
if quantity > 0:
quantity, warning = self._verify_updated_quantity(
order_line, product_id, quantity, **kwargs