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)
|
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):
|
class AuthenticatorPlugin(MessagePlugin):
|
||||||
"""Handle message authentication.
|
"""Handle message authentication.
|
||||||
|
|
||||||
@@ -90,6 +105,8 @@ class BaseService(object):
|
|||||||
credentials.Username = configuration.username
|
credentials.Username = configuration.username
|
||||||
credentials.Password = configuration.password
|
credentials.Password = configuration.password
|
||||||
self.plugin = AuthenticatorPlugin(credentials, self.client)
|
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.client.set_options(plugins=[self.plugin], port=configuration.port)
|
||||||
self.logger = getLogger("stamps")
|
self.logger = getLogger("stamps")
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ from .api.services import StampsService
|
|||||||
|
|
||||||
_logger = getLogger(__name__)
|
_logger = getLogger(__name__)
|
||||||
|
|
||||||
|
STAMPS_US_APO_FPO_STATE_CODES = (
|
||||||
|
'AE',
|
||||||
|
'AP',
|
||||||
|
'AA',
|
||||||
|
)
|
||||||
|
|
||||||
STAMPS_PACKAGE_TYPES = [
|
STAMPS_PACKAGE_TYPES = [
|
||||||
'Unknown',
|
'Unknown',
|
||||||
'Postcard',
|
'Postcard',
|
||||||
@@ -52,16 +58,22 @@ class ProductPackaging(models.Model):
|
|||||||
class ProviderStamps(models.Model):
|
class ProviderStamps(models.Model):
|
||||||
_inherit = 'delivery.carrier'
|
_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_username = fields.Char(string='Stamps.com Username', groups='base.group_system')
|
||||||
stamps_password = fields.Char(string='Stamps.com Password', 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'),
|
stamps_service_type = fields.Selection([('US-FC', 'USPS First-Class'),
|
||||||
('US-FCI', 'First-Class International'),
|
('US-PM', 'USPS Priority'),
|
||||||
('US-PM', 'Priority'),
|
('US-XM', 'USPS Express'),
|
||||||
('US-PMI', 'Priority Mail International'),
|
('US-MM', 'USPS Media Mail'),
|
||||||
('US-EMI', ' Priority Mail Express International'),
|
('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")
|
required=True, string="Service Type", default="US-PM")
|
||||||
stamps_default_packaging_id = fields.Many2one('product.packaging', string='Default Package Type')
|
stamps_default_packaging_id = fields.Many2one('product.packaging', string='Default Package Type')
|
||||||
@@ -78,7 +90,8 @@ class ProviderStamps(models.Model):
|
|||||||
('AZpl', 'AZPL'),
|
('AZpl', 'AZPL'),
|
||||||
('BZpl', 'BZPL'),
|
('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_sc = fields.Boolean(string='Add Signature Confirmation')
|
||||||
stamps_addon_dc = fields.Boolean(string='Add Delivery Confirmation')
|
stamps_addon_dc = fields.Boolean(string='Add Delivery Confirmation')
|
||||||
stamps_addon_hp = fields.Boolean(string='Add Hidden Postage')
|
stamps_addon_hp = fields.Boolean(string='Add Hidden Postage')
|
||||||
@@ -117,7 +130,7 @@ class ProviderStamps(models.Model):
|
|||||||
def _stamps_convert_weight(self, weight):
|
def _stamps_convert_weight(self, weight):
|
||||||
""" weight always expressed in database units (KG/LBS) """
|
""" 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:
|
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
|
get_param = self.env['ir.config_parameter'].sudo().get_param
|
||||||
product_weight_in_lbs_param = get_param('product.weight_in_lbs')
|
product_weight_in_lbs_param = get_param('product.weight_in_lbs')
|
||||||
@@ -307,8 +320,9 @@ class ProviderStamps(models.Model):
|
|||||||
return result
|
return result
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _stamps_needs_customs(self, from_partner, to_partner):
|
def _stamps_needs_customs(self, from_partner, to_partner, picking=None):
|
||||||
return from_partner.country_id.code != to_partner.country_id.code
|
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):
|
def stamps_send_shipping(self, pickings):
|
||||||
res = []
|
res = []
|
||||||
@@ -323,7 +337,7 @@ class ProviderStamps(models.Model):
|
|||||||
company, from_partner, to_partner = self._stamps_get_addresses_for_picking(picking)
|
company, from_partner, to_partner = self._stamps_get_addresses_for_picking(picking)
|
||||||
|
|
||||||
customs = None
|
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()
|
customs = service.create_customs()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user