details: https://code.tryton.org/tryton/commit/f5c8d570a98d
branch: default
user: Cédric Krier <[email protected]>
date: Thu Aug 14 12:56:41 2025 +0200
description:
Add button to update the sales from their web shop
Closes #14163
diffstat:
modules/web_shop/CHANGELOG | 1 +
modules/web_shop/sale.py | 15 ++++++++++++++-
modules/web_shop/sale.xml | 10 ++++++++++
modules/web_shop/view/sale_form.xml | 3 +++
modules/web_shop/web.py | 3 +++
modules/web_shop_shopify/web.py | 5 +++++
6 files changed, 36 insertions(+), 1 deletions(-)
diffs (107 lines):
diff -r 27ce1583f0b1 -r f5c8d570a98d modules/web_shop/CHANGELOG
--- a/modules/web_shop/CHANGELOG Thu Oct 09 10:20:31 2025 +0200
+++ b/modules/web_shop/CHANGELOG Thu Aug 14 12:56:41 2025 +0200
@@ -1,3 +1,4 @@
+* Add button to update the sales from their web shop
* Add web shop URLs to products
Version 7.6.0 - 2025-04-28
diff -r 27ce1583f0b1 -r f5c8d570a98d modules/web_shop/sale.py
--- a/modules/web_shop/sale.py Thu Oct 09 10:20:31 2025 +0200
+++ b/modules/web_shop/sale.py Thu Aug 14 12:56:41 2025 +0200
@@ -1,12 +1,13 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
+from itertools import groupby
from secrets import token_hex
from sql.conditionals import NullIf
from sql.operators import Equal
from trytond.i18n import gettext
-from trytond.model import Exclude, fields
+from trytond.model import Exclude, ModelView, fields
from trytond.modules.sale.exceptions import SaleValidationError
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Bool, Eval
@@ -34,6 +35,12 @@
(NullIf(t.web_id, ''), Equal)),
'web_shop.msg_sale_web_shop_id_unique')
]
+ cls._buttons.update({
+ 'web_shop_update': {
+ 'invisible': ~Eval('web_shop', None),
+ 'depends': ['web_shop'],
+ },
+ })
@classmethod
def __register__(cls, module):
@@ -74,3 +81,9 @@
gettext('web_shop.msg_sale_invalid_party',
sale=sale.rec_name,
party=sale.party.rec_name))
+
+ @classmethod
+ @ModelView.button
+ def web_shop_update(cls, sales):
+ for web_shop, s_sales in groupby(sales, lambda s: s.web_shop):
+ web_shop.update_sales(list(s_sales))
diff -r 27ce1583f0b1 -r f5c8d570a98d modules/web_shop/sale.xml
--- a/modules/web_shop/sale.xml Thu Oct 09 10:20:31 2025 +0200
+++ b/modules/web_shop/sale.xml Thu Aug 14 12:56:41 2025 +0200
@@ -14,5 +14,15 @@
<field name="inherit" ref="sale.sale_view_form"/>
<field name="name">sale_form</field>
</record>
+
+ <record model="ir.model.button" id="sale_web_shop_update_button">
+ <field name="model">sale.sale</field>
+ <field name="name">web_shop_update</field>
+ <field name="string">Update from Web Shop</field>
+ </record>
+ <record model="ir.model.button-res.group"
id="sale_web_shop_update_button_group_sale_admin">
+ <field name="button" ref="sale_web_shop_update_button"/>
+ <field name="group" ref="sale.group_sale_admin"/>
+ </record>
</data>
</tryton>
diff -r 27ce1583f0b1 -r f5c8d570a98d modules/web_shop/view/sale_form.xml
--- a/modules/web_shop/view/sale_form.xml Thu Oct 09 10:20:31 2025 +0200
+++ b/modules/web_shop/view/sale_form.xml Thu Aug 14 12:56:41 2025 +0200
@@ -8,4 +8,7 @@
<label name="web_id"/>
<field name="web_id"/>
</xpath>
+ <xpath expr="//button[@name='process']" position="after">
+ <button name="web_shop_update"/>
+ </xpath>
</data>
diff -r 27ce1583f0b1 -r f5c8d570a98d modules/web_shop/web.py
--- a/modules/web_shop/web.py Thu Oct 09 10:20:31 2025 +0200
+++ b/modules/web_shop/web.py Thu Aug 14 12:56:41 2025 +0200
@@ -259,6 +259,9 @@
sale.shipment_method = 'order'
return sale
+ def update_sales(self, sales):
+ assert all(s.web_shop == self for s in sales)
+
class Shop_PriceList(metaclass=PoolMeta):
__name__ = 'web.shop'
diff -r 27ce1583f0b1 -r f5c8d570a98d modules/web_shop_shopify/web.py
--- a/modules/web_shop_shopify/web.py Thu Oct 09 10:20:31 2025 +0200
+++ b/modules/web_shop_shopify/web.py Thu Aug 14 12:56:41 2025 +0200
@@ -125,6 +125,11 @@
sale.invoice_method = 'shipment'
return sale
+ def update_sales(self, sales):
+ super().update_sales(sales)
+ if self.type == 'shopify':
+ self._shopify_update_order(self, sales)
+
def shopify_session(self):
return shopify.Session.temp(
self.shopify_url, self.shopify_version, self.shopify_password)