[MIG] connector_amazon_sp: partial 14.0

Need to investigate form for Amazon orders.  Installing it complains that `action_...` doesn't actually exist.  I started making pass through methods like `action_unlock` in sale_order.common, but then came to an action that would only exist in inherited views and not in this specific new form.
This commit is contained in:
Jared Kipe
2022-02-04 15:23:27 -08:00
parent bf7192f71a
commit 5944db313e
17 changed files with 58 additions and 113 deletions

3
.gitmodules vendored
View File

@@ -41,3 +41,6 @@
[submodule "external/hibou-oca/product-attribute"]
path = external/hibou-oca/product-attribute
url = https://github.com/hibou-io/oca-product-attribute.git
[submodule "external/python-amazon-sp-api"]
path = external/python-amazon-sp-api
url = https://github.com/hibou-io/python-amazon-sp-api.git

View File

@@ -1,9 +1,8 @@
{
"name": "Amazon Selling Partner Connector",
"version": "11.0.1.0.0",
"version": "14.0.1.0.0",
"depends": [
"connector_ecommerce",
"sale_order_dates",
"sale_sourced_by_line",
"delivery_hibou",
"sale_planner",

View File

@@ -84,8 +84,7 @@ Resolution:
Check your taxes and fiscal positions configuration and correct them if necessary.</field>
<field name="sequence">30</field>
<field name="model">sale.order</field>
<field name="rule_group">sale</field>
<field name="code">failed = sale.amazon_bind_ids and abs(sale.amount_total - sale.amazon_bind_ids[0].total_amount) >= 0.01</field>
<field name="code">failed = object.amazon_bind_ids and abs(object.amount_total - object.amazon_bind_ids[0].total_amount) >= 0.01</field>
<field name="active" eval="True"/>
</record>

View File

@@ -124,7 +124,6 @@ class AmazonBackend(models.Model):
)
@contextmanager
@api.multi
def work_on(self, model_name, **kwargs):
self.ensure_one()
amazon_api = self.get_wrapped_api()
@@ -180,12 +179,10 @@ class AmazonBackend(models.Model):
for backend in backends:
self.env['amazon.product.product'].update_price(backend)
@api.multi
def import_sale_orders(self):
self._import_from_date('amazon.sale.order', 'import_orders_from_date')
return True
@api.multi
def _import_from_date(self, model_name, from_date_field):
import_start_time = datetime.now().replace(microsecond=0) - timedelta(seconds=IMPORT_DELTA_BUFFER)
for backend in self:

View File

@@ -1,7 +1,6 @@
# © 2021 Hibou Corp.
from odoo import api, models, fields
from odoo.addons.queue_job.job import job, related_action
class AmazonBinding(models.AbstractModel):
@@ -26,7 +25,6 @@ class AmazonBinding(models.AbstractModel):
('Amazon_uniq', 'unique(backend_id, external_id)', 'A binding already exists for this Amazon ID.'),
]
@job(default_channel='root.amazon')
@api.model
def import_batch(self, backend, filters=None):
""" Prepare the import of records modified on Amazon """
@@ -36,29 +34,9 @@ class AmazonBinding(models.AbstractModel):
importer = work.component(usage='batch.importer')
return importer.run(filters=filters)
@job(default_channel='root.amazon')
@related_action(action='related_action_unwrap_binding')
@api.model
def import_record(self, backend, external_id, force=False):
""" Import a Amazon record """
with backend.work_on(self._name) as work:
importer = work.component(usage='record.importer')
return importer.run(external_id, force=force)
# @job(default_channel='root.amazon')
# @related_action(action='related_action_unwrap_binding')
# @api.multi
# def export_record(self, fields=None):
# """ Export a record on Amazon """
# self.ensure_one()
# with self.backend_id.work_on(self._name) as work:
# exporter = work.component(usage='record.exporter')
# return exporter.run(self, fields)
#
# @job(default_channel='root.amazon')
# @related_action(action='related_action_amazon_link')
# def export_delete_record(self, backend, external_id):
# """ Delete a record on Amazon """
# with backend.work_on(self._name) as work:
# deleter = work.component(usage='record.exporter.deleter')
# return deleter.run(external_id)

View File

@@ -5,7 +5,6 @@ from base64 import b64encode, b64decode
from json import loads, dumps
from odoo import models, fields, api
from odoo.addons.queue_job.job import job
from odoo.addons.component.core import Component
from odoo.addons.queue_job.exception import RetryableJobError
@@ -59,8 +58,6 @@ class AmazonFeed(models.Model):
string='Listing',
ondelete='set null')
@api.multi
@job(default_channel='root.amazon')
def submit_feed(self):
for feed in self:
api_instance = feed.backend_id.get_wrapped_api()
@@ -80,8 +77,6 @@ class AmazonFeed(models.Model):
# The rest will be delayed 30 min each
feed.with_delay(priority=100).check_feed()
@api.multi
@job(default_channel='root.amazon', retry_pattern=FEED_RETRY_PATTERN)
def check_feed(self):
for feed in self.filtered('external_id'):
api_instance = feed.backend_id.get_wrapped_api()
@@ -106,7 +101,6 @@ class AmazonFeed(models.Model):
# queue a job to process the response
feed.with_delay(priority=10).process_feed_result()
@job(default_channel='root.amazon')
def process_feed_result(self):
for feed in self:
pass

View File

@@ -5,7 +5,6 @@ from Crypto.Util.Padding import pad
from base64 import b64decode, b64encode
from odoo import api
from odoo.tools import pycompat
PREFIX = 'amz_pii:'
PREFIX_LEN = len(PREFIX)
@@ -17,7 +16,7 @@ AMZ_PII_DECRYPT_FAIL = -1
def make_amz_pii_decrypt(cipher):
def amz_pii_decrypt(value):
if value and isinstance(value, pycompat.string_types) and value.startswith(PREFIX):
if value and isinstance(value, str) and value.startswith(PREFIX):
try:
to_decrypt = b64decode(value[PREFIX_LEN:])
# remove whitespace and `ack`
@@ -32,7 +31,7 @@ def make_amz_pii_decrypt(cipher):
def make_amz_pii_encrypt(cipher):
def amz_pii_encrypt(value):
if value and isinstance(value, pycompat.string_types) and not value.startswith(PREFIX):
if value and isinstance(value, str) and not value.startswith(PREFIX):
try:
to_encrypt = value.encode()
to_encrypt = pad(to_encrypt, BLOCK_SIZE)
@@ -112,6 +111,7 @@ def make_amz_pii_cipher(env):
def update(self, records, field, values):
""" Set the values of ``field`` for several ``records``. """
amz_pii_decrypt = getattr(self, 'amz_pii_decrypt', None)
amz_pii_decrypt_enabled = records.env.context.get('amz_pii_decrypt')
if not amz_pii_decrypt and amz_pii_decrypt_enabled:
@@ -120,8 +120,10 @@ def update(self, records, field, values):
for i, value in enumerate(values):
values[i] = amz_pii_decrypt(value)
key = records.env.cache_key(field)
self._data[key][field].update(pycompat.izip(records._ids, values))
field_cache = self._data[field]
if field.depends_context:
field_cache = field_cache.setdefault(records.env.cache_key(field), {})
field_cache.update(zip(records._ids, values))
def _start_amz_pii_decrypt(self, env):

View File

@@ -25,7 +25,7 @@ class ProviderAmazonSP(models.Model):
delivery_type = fields.Selection(selection_add=[
# ('amazon_sp', 'Amazon Selling Partner'), # TODO buy shipping for regular orders?
('amazon_sp_mfn', 'Amazon SP Merchant Fulfillment')
])
], ondelete={'amazon_sp_mfn': lambda recs: recs.write({'delivery_type': 'fixed', 'fixed_price': 0})})
# Fields when uploading shipping to Amazon
amazon_sp_carrier_code = fields.Char(string='Amazon Carrier Code',

View File

@@ -50,7 +50,6 @@ class AmazonProductProduct(models.Model):
for product in other:
product.external_id = product.external_id
@api.multi
def button_submit_product(self):
backends = self.mapped('backend_id')
for backend in backends:
@@ -58,7 +57,6 @@ class AmazonProductProduct(models.Model):
products._submit_product()
return 1
@api.multi
def button_update_inventory(self):
backends = self.mapped('backend_id')
for backend in backends:
@@ -66,7 +64,6 @@ class AmazonProductProduct(models.Model):
products._update_inventory()
return 1
@api.multi
def button_update_price(self):
backends = self.mapped('backend_id')
for backend in backends:

View File

@@ -7,7 +7,6 @@ import odoo.addons.decimal_precision as dp
from odoo import models, fields, api
from odoo.exceptions import ValidationError
from odoo.addons.queue_job.job import job, related_action
from odoo.addons.component.core import Component
from odoo.addons.queue_job.exception import RetryableJobError
@@ -72,19 +71,15 @@ class AmazonSaleOrder(models.Model):
for so in self:
so.is_amazon_order = True
@job(default_channel='root.amazon')
@api.model
def import_batch(self, backend, filters=None):
""" Prepare the import of Sales Orders from Amazon """
return super(AmazonSaleOrder, self).import_batch(backend, filters=filters)
@job(default_channel='root.amazon', retry_pattern=SO_IMPORT_RETRY_PATTERN)
@related_action(action='related_action_unwrap_binding')
@api.model
def import_record(self, backend, external_id, force=False):
return super().import_record(backend, external_id, force=force)
@api.multi
def action_confirm(self):
res = self.odoo_id.action_confirm()
if res and hasattr(res, '__getitem__'): # Button returned an action: we need to set active_id to the amazon sale order
@@ -96,15 +91,12 @@ class AmazonSaleOrder(models.Model):
})
return res
@api.multi
def action_cancel(self):
return self.odoo_id.action_cancel()
@api.multi
def action_draft(self):
return self.odoo_id.action_draft()
@api.multi
def action_view_delivery(self):
res = self.odoo_id.action_view_delivery()
res.update({
@@ -115,12 +107,8 @@ class AmazonSaleOrder(models.Model):
})
return res
# @job(default_channel='root.amazon')
# @api.model
# def acknowledge_order(self, backend, external_id):
# with backend.work_on(self._name) as work:
# adapter = work.component(usage='backend.adapter')
# return adapter.acknowledge_order(external_id)
def action_unlock(self):
return self.odoo_id.action_unlock()
class SaleOrder(models.Model):
@@ -158,12 +146,6 @@ class SaleOrder(models.Model):
for so in self:
so.is_amazon_order = False
# @api.multi
# def action_confirm(self):
# res = super(SaleOrder, self).action_confirm()
# self.amazon_bind_ids.action_confirm()
# return res
class AmazonSaleOrderLine(models.Model):
_name = 'amazon.sale.order.line'

View File

@@ -3,7 +3,6 @@
from base64 import b64encode
from odoo import api, models, fields, _
from odoo.addons.queue_job.job import job, related_action
from odoo.addons.component.core import Component
import logging
@@ -24,9 +23,6 @@ class AmazonStockPicking(models.Model):
string='Amazon Sale Order',
ondelete='set null')
@job(default_channel='root.amazon')
@related_action(action='related_action_unwrap_binding')
@api.multi
def export_picking_done(self):
""" Export a complete or partial delivery order. """
self.ensure_one()

View File

@@ -106,7 +106,7 @@
</p>
<group>
<div>
<label string="Import sale orders since" class="oe_inline"/>
<label for="import_orders_from_date" string="Import sale orders since" class="oe_inline"/>
<field name="import_orders_from_date"
class="oe_inline"
nolabel="1"/>
@@ -139,7 +139,6 @@
<record id="action_amazon_backend" model="ir.actions.act_window">
<field name="name">Amazon Backends</field>
<field name="res_model">amazon.backend</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_amazon_backend_tree"/>
</record>

View File

@@ -55,7 +55,6 @@
<record id="action_amazon_feed" model="ir.actions.act_window">
<field name="name">Amazon SP Feeds</field>
<field name="res_model">amazon.feed</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>

View File

@@ -61,7 +61,6 @@
<record id="action_amazon_product_product" model="ir.actions.act_window">
<field name="name">Amazon SP Listings</field>
<field name="res_model">amazon.product.product</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>

View File

@@ -41,7 +41,7 @@
<field name="effective_date"/>
<field name="date_planned"/>
<field name="requested_date"/>
<field name="confirmation_date"/>
<field name="date_order"/>
<field name="amount_total" sum="Total Tax Included" widget="monetary"/>
<field name="total_amount" sum="Amazon Total Tax Included" widget="monetary" string="Amazon Total"/>
<field name="currency_id" invisible="1"/>
@@ -51,45 +51,44 @@
</field>
</record>
<record id="view_amazon_order_form" model="ir.ui.view">
<field name="name">amazon.sale.order.form</field>
<field name="model">amazon.sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="mode">primary</field>
<field name="arch" type="xml">
<xpath expr="//header" position="replace">
<header>
<button name="action_confirm" id="action_confirm" string="Confirm Sale" class="btn-primary" type="object" attrs="{'invisible': [('state', 'not in', ['draft', 'sent'])]}"/>
<button name="action_cancel" states="draft,sent,sale" type="object" string="Cancel"/>
<button name="action_draft" states="cancel" type="object" string="Set to Quotation"/>
<button name="action_unlock" type="object" string="Unlock" states="done" groups="sales_team.group_sale_manager"/>
<field name="state" widget="statusbar" statusbar_visible="draft,sent,sale"/>
</header>
</xpath>
<xpath expr="//sheet/group/group[1]" position="inside">
<field name="fulfillment_channel"/>
<field name="is_prime"/>
<field name="is_business_order"/>
<field name="is_global_express_enabled"/>
<field name="is_premium"/>
<field name="is_sold_by_ab"/>
</xpath>
<xpath expr="//sheet/group/group[2]" position="inside">
<field name="ship_service_level"/>
<field name="ship_service_level_category"/>
<field name="marketplace"/>
<field name="order_type"/>
</xpath>
<xpath expr="//field[@name='amount_total']" position="after">
<field name="total_amount" string="Amazon Total" widget="monetary"/>
</xpath>
</field>
</record>
<!-- <record id="view_amazon_order_form" model="ir.ui.view">-->
<!-- <field name="name">amazon.sale.order.form</field>-->
<!-- <field name="model">amazon.sale.order</field>-->
<!-- <field name="inherit_id" ref="sale.view_order_form"/>-->
<!-- <field name="mode">primary</field>-->
<!-- <field name="arch" type="xml">-->
<!-- <xpath expr="//header" position="replace">-->
<!-- <header>-->
<!-- <button name="action_confirm" id="action_confirm" string="Confirm Sale" class="btn-primary" type="object" attrs="{'invisible': [('state', 'not in', ['draft', 'sent'])]}"/>-->
<!-- <button name="action_cancel" states="draft,sent,sale" type="object" string="Cancel"/>-->
<!-- <button name="action_draft" states="cancel" type="object" string="Set to Quotation"/>-->
<!-- <button name="action_unlock" type="object" string="Unlock" states="done" groups="sales_team.group_sale_manager"/>-->
<!-- <field name="state" widget="statusbar" statusbar_visible="draft,sent,sale"/>-->
<!-- </header>-->
<!-- </xpath>-->
<!-- <xpath expr="//sheet/group/group[1]" position="inside">-->
<!-- <field name="fulfillment_channel"/>-->
<!-- <field name="is_prime"/>-->
<!-- <field name="is_business_order"/>-->
<!-- <field name="is_global_express_enabled"/>-->
<!-- <field name="is_premium"/>-->
<!-- <field name="is_sold_by_ab"/>-->
<!-- </xpath>-->
<!-- <xpath expr="//sheet/group/group[2]" position="inside">-->
<!-- <field name="ship_service_level"/>-->
<!-- <field name="ship_service_level_category"/>-->
<!-- <field name="marketplace"/>-->
<!-- <field name="order_type"/>-->
<!-- </xpath>-->
<!-- <xpath expr="//field[@name='amount_total']" position="after">-->
<!-- <field name="total_amount" string="Amazon Total" widget="monetary"/>-->
<!-- </xpath>-->
<!-- </field>-->
<!-- </record>-->
<record id="action_amazon_orders" model="ir.actions.act_window">
<field name="name">Amazon SP Orders</field>
<field name="res_model">amazon.sale.order</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_amazon_order_tree"/>
</record>

View File

@@ -8,10 +8,11 @@
</xpath>
</template>
<template id="report_delivery_document_inherit" inherit_id="stock.report_delivery_document">
<xpath expr="//div[@name='customer_address']" position="attributes">
<attribute name="t-if">not o.has_amazon_pii()</attribute>
</xpath>
</template>
<!-- xpath error -->
<!-- <template id="report_delivery_document_inherit" inherit_id="stock.report_delivery_document">-->
<!-- <xpath expr="//div[@name='customer_address']" position="attributes">-->
<!-- <attribute name="t-if">not o.has_amazon_pii()</attribute>-->
<!-- </xpath>-->
<!-- </template>-->
</odoo>