mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[IMP] delivery_stamps: add GlobalPost methods and APO/FPO
This commit is contained in:
@@ -28,6 +28,21 @@ PATTERN_ID = r"{hex}{{8}}-{hex}{{4}}-{hex}{{4}}-{hex}{{4}}-{hex}{{12}}".format(
|
||||
RE_TRANSACTION_ID = compile(PATTERN_ID)
|
||||
|
||||
|
||||
# class LogPlugin(MessagePlugin):
|
||||
# def __init__(self):
|
||||
# self.logger = getLogger('stamps2')
|
||||
# self.last_sent_raw = None
|
||||
# self.last_received_raw = None
|
||||
#
|
||||
# def sending(self, context):
|
||||
# self.last_sent_raw = str(context.envelope)
|
||||
# self.logger.warning(self.last_sent_raw)
|
||||
#
|
||||
# def received(self, context):
|
||||
# self.last_received_raw = str(context.reply)
|
||||
# self.logger.warning(self.last_received_raw)
|
||||
|
||||
|
||||
class AuthenticatorPlugin(MessagePlugin):
|
||||
"""Handle message authentication.
|
||||
|
||||
@@ -90,6 +105,8 @@ class BaseService(object):
|
||||
credentials.Username = configuration.username
|
||||
credentials.Password = configuration.password
|
||||
self.plugin = AuthenticatorPlugin(credentials, self.client)
|
||||
# put in plugins=[] as well
|
||||
# self.logplugin = LogPlugin()
|
||||
self.client.set_options(plugins=[self.plugin], port=configuration.port)
|
||||
self.logger = getLogger("stamps")
|
||||
|
||||
|
||||
@@ -14,6 +14,12 @@ from .api.services import StampsService
|
||||
|
||||
_logger = getLogger(__name__)
|
||||
|
||||
STAMPS_US_APO_FPO_STATE_CODES = (
|
||||
'AE',
|
||||
'AP',
|
||||
'AA',
|
||||
)
|
||||
|
||||
STAMPS_PACKAGE_TYPES = [
|
||||
'Unknown',
|
||||
'Postcard',
|
||||
@@ -52,16 +58,22 @@ class ProductPackaging(models.Model):
|
||||
class ProviderStamps(models.Model):
|
||||
_inherit = 'delivery.carrier'
|
||||
|
||||
delivery_type = fields.Selection(selection_add=[('stamps', 'Stamps.com (USPS)')])
|
||||
delivery_type = fields.Selection(selection_add=[('stamps', 'Stamps.com')])
|
||||
|
||||
stamps_username = fields.Char(string='Stamps.com Username', groups='base.group_system')
|
||||
stamps_password = fields.Char(string='Stamps.com Password', groups='base.group_system')
|
||||
|
||||
stamps_service_type = fields.Selection([('US-FC', 'First-Class'),
|
||||
('US-FCI', 'First-Class International'),
|
||||
('US-PM', 'Priority'),
|
||||
('US-PMI', 'Priority Mail International'),
|
||||
('US-EMI', ' Priority Mail Express International'),
|
||||
stamps_service_type = fields.Selection([('US-FC', 'USPS First-Class'),
|
||||
('US-PM', 'USPS Priority'),
|
||||
('US-XM', 'USPS Express'),
|
||||
('US-MM', 'USPS Media Mail'),
|
||||
('US-FCI', 'USPS First-Class International'),
|
||||
('US-PMI', 'USPS Priority International'),
|
||||
('US-EMI', 'USPS Express International'),
|
||||
('SC-GPE', 'GlobalPost Economy'),
|
||||
('SC-GPP', 'GlobalPost Standard'),
|
||||
('SC-GPESS', 'GlobalPost SmartSaver Economy'),
|
||||
('SC-GPPSS', 'GlobalPost SmartSaver Standard'),
|
||||
],
|
||||
required=True, string="Service Type", default="US-PM")
|
||||
stamps_default_packaging_id = fields.Many2one('product.packaging', string='Default Package Type')
|
||||
@@ -78,7 +90,8 @@ class ProviderStamps(models.Model):
|
||||
('AZpl', 'AZPL'),
|
||||
('BZpl', 'BZPL'),
|
||||
],
|
||||
required=True, string="Image Type", default="Pdf")
|
||||
required=True, string="Image Type", default="Pdf",
|
||||
help='Generally PDF or ZPL are the great options.')
|
||||
stamps_addon_sc = fields.Boolean(string='Add Signature Confirmation')
|
||||
stamps_addon_dc = fields.Boolean(string='Add Delivery Confirmation')
|
||||
stamps_addon_hp = fields.Boolean(string='Add Hidden Postage')
|
||||
@@ -117,7 +130,7 @@ class ProviderStamps(models.Model):
|
||||
def _stamps_convert_weight(self, weight):
|
||||
""" weight always expressed in database units (KG/LBS) """
|
||||
if self.stamps_default_packaging_id.max_weight and self.stamps_default_packaging_id.max_weight < weight:
|
||||
raise ValidationError('Stamps cannot ship for weight: ' + str(weight) + ' kgs/lbs.')
|
||||
raise ValidationError('Your Package Type cannot ship for weight: ' + str(weight) + ' kgs/lbs. Max: ' + str(self.stamps_default_packaging_id.max_weight))
|
||||
|
||||
get_param = self.env['ir.config_parameter'].sudo().get_param
|
||||
product_weight_in_lbs_param = get_param('product.weight_in_lbs')
|
||||
@@ -307,8 +320,9 @@ class ProviderStamps(models.Model):
|
||||
return result
|
||||
return result
|
||||
|
||||
def _stamps_needs_customs(self, from_partner, to_partner):
|
||||
return from_partner.country_id.code != to_partner.country_id.code
|
||||
def _stamps_needs_customs(self, from_partner, to_partner, picking=None):
|
||||
return from_partner.country_id.code != to_partner.country_id.code or \
|
||||
(to_partner.country_id.code == 'US' and to_partner.state_id.code in STAMPS_US_APO_FPO_STATE_CODES)
|
||||
|
||||
def stamps_send_shipping(self, pickings):
|
||||
res = []
|
||||
@@ -323,7 +337,7 @@ class ProviderStamps(models.Model):
|
||||
company, from_partner, to_partner = self._stamps_get_addresses_for_picking(picking)
|
||||
|
||||
customs = None
|
||||
if self._stamps_needs_customs(from_partner, to_partner):
|
||||
if self._stamps_needs_customs(from_partner, to_partner, picking=picking):
|
||||
customs = service.create_customs()
|
||||
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user