diff --git a/data/data.xml b/data/data.xml
index 37c0acd..a05339f 100644
--- a/data/data.xml
+++ b/data/data.xml
@@ -7,7 +7,7 @@
20
0.70
0.020
- False
+ 0
Kompaktbrief
@@ -15,7 +15,7 @@
11
0.85
0.050
- False
+ 0
Großbrief
@@ -23,7 +23,7 @@
21
1.45
0.500
- False
+ 0
Maxibrief
@@ -31,7 +31,7 @@
31
2.60
1.000
- False
+ 0
Maxibrief bis 2000 g + Zusatzentgelt MBf
@@ -39,17 +39,25 @@
41
4.80
2.000
- False
+ 0
+
+ Kompaktbrief Integral + EINSCHREIBEN
+ Kompakt Natl EIN
+ 1017
+ 3.95
+ 0.050
+ 0
+
Großbrief Integral + EINSCHREIBEN
Gross Natl EIN
1027
3.95
0.500
- False
+ 0
Maxibrief Integral + EINSCHREIBEN
@@ -57,15 +65,25 @@
1037
5.10
1.000
- False
+ 0
+
+ Maxibrief Integral + EINSCHREIBEN EINWURF + Zusatzentgelt MBf
+ Maxi Natl 2kg EIN
+ 1042
+ 6.95
+ 2.000
+ 0
+
+
+
Großbrief Integral + EINSCHREIBEN EINWURF
Gross Natl WURF
1022
3.60
0.500
- False
+ 0
Maxibrief Integral + EINSCHREIBEN EINWURF
@@ -73,17 +91,65 @@
1032
4.75
1.000
- False
+ 0
+
+ Standardbrief Intern. GK Integral + EINSCHREIBEN
+ Standart Intl EIN
+ 11006
+ 3.40
+ 0.020
+ 1
+
+
+ Kompaktbrief Intern. GK
+ Kompakt Intl
+ 10011
+ 1.50
+ 0.050
+ 1
+
+
+ Großbrief Intern. GK
+ Gross Intl
+ 10051
+ 3.70
+ 0.500
+ 1
+
+
+ Maxibrief Intern. bis 1.000g GK
+ Maxi Intl 1kg
+ 10071
+ 7.00
+ 1.000
+ 1
+
+
+ Maxibrief Intern. bis 2.000g GK
+ Maxi Intl 2kg
+ 10091
+ 17.00
+ 2.000
+ 1
+
+
+ Standardbrief Intern. GK Integral + EINSCHREIBEN
+ Standart Intl EIN
+ 11006
+ 3.40
+ 0.020
+ 1
+
Kompaktbrief Intern. GK Integral + EINSCHREIBEN
Kompakt Intl EIN
11016
4.00
0.050
- True
+ 1
Großbrief Intern. GK Integral + EINSCHREIBEN
@@ -91,7 +157,7 @@
11056
6.20
0.500
- True
+ 1
Maxibrief Intern. bis 1.000g GK Integral + EINSCHREIBEN
@@ -99,7 +165,7 @@
11076
9.50
1.000
- True
+ 1
Maxibrief Intern. bis 2.000g GK Integral + EINSCHREIBEN
@@ -107,8 +173,33 @@
11096
19.50
2.000
- True
+ 1
+
+ Standard
+
+
+
+
+ Registered
+
+
+
diff --git a/data/delivery_demo.xml b/data/delivery_demo.xml
index d9e13a7..4e3b15b 100644
--- a/data/delivery_demo.xml
+++ b/data/delivery_demo.xml
@@ -15,21 +15,38 @@
0.0
0.0
-
- Deutsche Post Brief
+
+ Deutsche Post Letter
0
dp
-
+
test
0
- False
- True
- False
+ 0
+ 1
+ 0
KG
+
+ Deutsche Post Registered Letter
+ 0
+ dp
+
+
+
+ test
+ 0
+ 0
+ 1
+ 0
+
+ KG
+
+
+
diff --git a/models/dp_delivery_carrier.py b/models/dp_delivery_carrier.py
index db3a4ca..1b1786c 100644
--- a/models/dp_delivery_carrier.py
+++ b/models/dp_delivery_carrier.py
@@ -77,17 +77,46 @@ class DPDeliveryCarrier(models.Model):
last = last,
address = addr)
+ def get_services_by_country(self, service_class, country_code):
+ if country_code == 'DE':
+ return service_class.services_natl
+ else:
+ return service_class.services_intl
+
+ # determine lowest-matching-max-weight service within same class
+ def get_service_by_class(self, recipient, weight, service_class):
+ services = self.get_services_by_country(service_class, recipient.country_id.code)
+ lowest_max_weight = 100000
+ lowest_service = None
+ for s in services:
+ if s.weight >= weight and s.weight < lowest_max_weight:
+ lowest_max_weight = s.weight
+ lowest_service = s
+ return lowest_service
+
+ # determine the maximum weight (in kg) of any service in this class
+ def get_class_max_weight(self, service_class):
+ services = self.get_services_by_country(service_class, recipient.country_id.code)
+ highest_weight = 0
+ for s in services:
+ if highest_weight > hightest_weight:
+ highest_weight = s.weight
+ return highest_weight
+
@api.one
def dp_send_shipping(self, pickings):
config = self._get_config()
order = self.env['sale.order'].search([('name','=',pickings.origin)])
recipient = pickings.partner_id
warehouse = pickings.picking_type_id.warehouse_id.partner_id
- service = self.sudo().dp_service_type
+ weight = self._get_weight(order, pickings)
+ service = self.get_service_by_class(recipient, weight, self.sudo().dp_service_class)
+ if not service:
+ raise Warning("Service not available for weight!")
im = self.conn_auth_im()
im_recipient = self.build_im_addr(im, recipient)
im_sender = self.build_im_addr(im, warehouse)
- service = self.sudo().dp_service_type
+ im.clear_positions()
position = im.build_position(service.code, im_sender, im_recipient)
im.add_position(position)
r = im.checkoutPNG()
@@ -107,12 +136,31 @@ class DPDeliveryCarrier(models.Model):
return result
def dp_get_shipping_price_from_so(self, order):
+ price = 0
config = self._get_config()
recipient = order.partner_shipping_id if order.partner_shipping_id else order.partner_id
warehouse = order.warehouse_id.partner_id
- service = self.sudo().dp_service_type
+ service_class = self.sudo().dp_service_class
+
+ # single-package implementation
+ weight = self._get_weight(order)
+ service = self.get_service_by_class(recipient, weight, service_class)
+ if not service:
+ raise Warning("Service not available for weight!")
return service.cost_price
+ # compute the maximum weight of any service within class
+ #class_max_weight = self.get_class_max_weight(service_class)
+ # compute number of packages and each weight
+ #weight, weight_limit, last_package, limits = self.get_package_count(class_max_weight, order)
+ # iterate over list of packages
+ #for line in range(1, limits+1):
+ # if last_package and line == limits:
+ # weight_limit = last_package
+ # service = self.get_service_by_class(recipient, weight, service_class)
+ # price += service.cost_price
+ #return price
+
@api.one
def dp_get_tracking_link(self, pickings):
return TRACKING_URL
diff --git a/models/dp_shipping_service.py b/models/dp_shipping_service.py
index f3be83d..2ce1062 100644
--- a/models/dp_shipping_service.py
+++ b/models/dp_shipping_service.py
@@ -4,7 +4,18 @@ from openerp import api, fields, models
class SMCShippingDp(models.Model):
_inherit="delivery.carrier"
delivery_type = fields.Selection(selection_add=[('dp','Deutsche Post')])
- dp_service_type = fields.Many2one(comodel_name = 'delivery.carrier.dp.service', string = 'DP Service')
+ dp_service_class = fields.Many2one(comodel_name = 'delivery.carrier.dp.class', string = 'DP Service Class')
+
+# New model for DP Classes (regular mail, registered mail, ...)
+class SMCShippingDpClass(models.Model):
+ _name = "delivery.carrier.dp.class"
+ name = fields.Char(string="Name", required=1)
+ # list of services in this class for national delivery
+ services_natl = fields.Many2many(comodel_name = 'delivery.carrier.dp.service',
+ relation = 'dp_class_natl_services_rel')
+ # list of services in this class for international delivery
+ services_intl = fields.Many2many(comodel_name = 'delivery.carrier.dp.service',
+ relation = 'dp_class_intl_services_rel')
# New model for DP Products/Services (from ProdWS)
class SMCShippingDpService(models.Model):
diff --git a/views/dp_delivery_carrier.xml b/views/dp_delivery_carrier.xml
index 0b1d957..6b6fe15 100644
--- a/views/dp_delivery_carrier.xml
+++ b/views/dp_delivery_carrier.xml
@@ -11,6 +11,7 @@
+
shipping.dp.form
delivery.carrier
@@ -19,12 +20,13 @@
-
+
+
delivery.carrier.dp.service.form
delivery.carrier.dp.service
@@ -69,6 +71,35 @@
+
+
+
+ delivery.carrier.dp.class.tree
+ delivery.carrier.dp.class
+ form
+
+
+
+
+
+ delivery.carrier.dp.class.tree
+ delivery.carrier.dp.class
+ tree
+
+
+
+
+
+
+
+
+
stock.picking.dp.shipping.search
stock.picking
@@ -86,7 +117,15 @@
tree,form
+
+ DP Class List
+ delivery.carrier.dp.class
+ form
+ tree,form
+
+
+