Add admin URL to Shopify identifiers

Closes #14160 #14164
This commit is contained in:
Cédric Krier
2025-08-14 14:31:32 +02:00
parent 047d89886b
commit 23b4ec2aad
13 changed files with 89 additions and 3 deletions
+1
View File
@@ -1,3 +1,4 @@
* Add admin URL to identifiers
* Set compare-at price using non-sale price
* Add support for product kit
* Add carrier selection
+19 -1
View File
@@ -1,8 +1,11 @@
# 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 urllib.parse import urljoin
from trytond.i18n import lazy_gettext
from trytond.model import fields
from trytond.pool import Pool
from trytond.pyson import Eval
def id2gid(resouce, id):
@@ -28,6 +31,12 @@ class IdentifierMixin:
lazy_gettext('web_shop_shopify.msg_shopify_identifier')),
'get_shopify_identifier', setter='set_shopify_identifier',
searcher='search_shopify_identifier')
shopify_url = fields.Function(fields.Char(
lazy_gettext('web_shop_shopify.msg_shopify_url'),
states={
'invisible': ~Eval('shopify_url'),
}),
'get_shopify_url')
def get_shopify_identifier(self, name):
if self.shopify_identifier_signed is not None:
@@ -54,6 +63,14 @@ class IdentifierMixin:
value = int(value) - (1 << 63)
return [('shopify_identifier_signed', operator, value)]
def get_shopify_url(self, name):
if (getattr(self, 'shopify_resource', None)
and getattr(self, 'web_shop', None)
and self.shopify_identifier_char):
return urljoin(
self.web_shop.shopify_url + '/admin/',
f'{self.shopify_resource}/{self.shopify_identifier_char}')
@classmethod
def copy(cls, records, default=None):
if default is None:
@@ -100,7 +117,8 @@ class IdentifiersMixin(IdentifiersUpdateMixin):
shopify_identifiers = fields.One2Many(
'web.shop.shopify_identifier', 'record',
lazy_gettext('web_shop_shopify.msg_shopify_identifiers'))
lazy_gettext('web_shop_shopify.msg_shopify_identifiers'),
readonly=True)
def get_shopify_identifier(self, web_shop):
for record in self.shopify_identifiers:
+3
View File
@@ -9,6 +9,9 @@ this repository contains the full copyright notices and license terms. -->
<record model="ir.message" id="msg_shopify_identifier">
<field name="text">Shopify Identifier</field>
</record>
<record model="ir.message" id="msg_shopify_url">
<field name="text">Shopify URL</field>
</record>
<record model="ir.message" id="msg_identifier_record_web_shop_unique">
<field name="text">The record cannot have more than one Shopify identifier per web shop.</field>
</record>
+12
View File
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tryton>
<data>
<record model="ir.ui.view" id="party_view_form">
<field name="model">party.party</field>
<field name="inherit" ref="party.party_view_form"/>
<field name="name">party_form</field>
</record>
</data>
</tryton>
+1
View File
@@ -154,6 +154,7 @@ class Sale(IdentifierMixin, metaclass=PoolMeta):
"Shopify Tax Adjustment",
currency='currency', digits='currency', readonly=True)
shopify_status_url = fields.Char("Shopify Status URL", readonly=True)
shopify_resource = 'orders'
@classmethod
def __setup__(cls):
+12
View File
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tryton>
<data>
<record model="ir.ui.view" id="sale_view_form">
<field name="model">sale.sale</field>
<field name="inherit" ref="sale.sale_view_form"/>
<field name="name">sale_form</field>
</record>
</data>
</tryton>
+2
View File
@@ -27,7 +27,9 @@ extras_depend:
xml:
ir.xml
product.xml
party.xml
web.xml
sale.xml
stock.xml
carrier.xml
message.xml
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="//field[@name='identifiers']" position="after">
<field name="shopify_identifiers" colspan="4"/>
</xpath>
</data>
@@ -11,5 +11,7 @@ this repository contains the full copyright notices and license terms. -->
<label name="shopify_handle"/>
<field name="shopify_handle"/>
<newline/>
<field name="shopify_identifiers" colspan="4"/>
</xpath>
</data>
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="//field[@name='web_id']" position="after">
<newline/>
<label name="shopify_url"/>
<field name="shopify_url" widget="url" colspan="3"/>
</xpath>
</data>
@@ -10,6 +10,8 @@ this repository contains the full copyright notices and license terms. -->
<label name="shopify_identifier"/>
<field name="shopify_identifier" width="20"/>
<label name="shopify_url"/>
<field name="shopify_url" widget="url"/>
<label name="to_update"/>
<field name="to_update"/>
</form>
@@ -4,7 +4,8 @@ this repository contains the full copyright notices and license terms. -->
<tree>
<field name="web_shop" expand="1"/>
<field name="record" expand="1"/>
<field name="shopify_identifier" expand="2"/>
<field name="to_update"/>
<field name="shopify_identifier" expand="2" optional="0"/>
<field name="shopify_url" widget="url"/>
<field name="to_update" optional="1"/>
<button name="set_to_update" tree_invisible="1"/>
</tree>
+14
View File
@@ -970,6 +970,20 @@ class ShopShopifyIdentifier(IdentifierMixin, ModelSQL, ModelView):
def set_to_update(cls, identifiers):
cls.write(identifiers, {'to_update': True})
@property
def shopify_resource(self):
if self.record.__name__ == 'product.product':
product_identifier = self.record.template.get_shopify_identifier(
self.web_shop)
resource = f'products/{product_identifier}/variants'
else:
resource = {
'party.party': 'customers',
'product.category': 'collections',
'product.template': 'products',
}.get(self.record.__name__)
return resource
class Shop_Warehouse(ModelView, metaclass=PoolMeta):
__name__ = 'web.shop-stock.location'