[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

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()