Browse Source

initial import of Odoo Internetmarke Code

for/master
Harald Welte 5 years ago
commit
14356e8203
  1. 1
      __init__.py
  2. 21
      __openerp__.py
  3. 98
      data/data.xml
  4. 20
      data/delivery_demo.xml
  5. 98
      models/dp_delivery_carrier.py
  6. 27
      models/dp_shipping_service.py
  7. 4
      security/ir.model.access.csv
  8. 75
      views/dp_delivery_carrier.xml
  9. 43
      views/res_config.xml

1
__init__.py

@ -0,0 +1 @@
import models

21
__openerp__.py

@ -0,0 +1,21 @@
{
'name': 'Deutsche Post Internetmarke Shipping Integration',
'category': 'Website/Shipping Logistics',
'summary': 'Integrate Deutsche Post shipping functionality directly within Odoo ERP applications to deliver increased logistical efficiencies.',
'website': '',
'version': '0.1',
'description':"""
""",
'author': 'Harald Welte',
'depends': ['odoo_shipping_service_apps'],
'data': [
'views/dp_delivery_carrier.xml',
'views/res_config.xml',
'data/data.xml',
'data/delivery_demo.xml',
'security/ir.model.access.csv',
]
'installable': True,
'application': True,
"images":['static/description/Banner.png']
}

98
data/data.xml

@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">·
<record forcecreate="True" id="dp_service_natl_sb" model="delivery.carrier.dp.service">
<field name="name">Standardbrief</field>
<field name="short_name">Standard Natl</field>
<field name="code">20</field>
<field name="cost_price">0.70</field>
<field name="weight">0.020</field>
<field name="international">False</field>
</record>
<record forcecreate="True" id="dp_service_natl_kb" model="delivery.carrier.dp.service">
<field name="name">Kompaktbrief</field>
<field name="short_name">Kompakt Natl</field>
<field name="code">11</field>
<field name="cost_price">0.85</field>
<field name="weight">0.050</field>
<field name="international">False</field>
</record>
<record forcecreate="True" id="dp_service_natl_gb" model="delivery.carrier.dp.service">
<field name="name">Großbrief</field>
<field name="short_name">Gross Natl</field>
<field name="code">21</field>
<field name="cost_price">1.45</field>
<field name="weight">0.500</field>
<field name="international">False</field>
</record>
<record forcecreate="True" id="dp_service_natl_mb1k" model="delivery.carrier.dp.service">
<field name="name">Maxibrief</field>
<field name="short_name">Maxi Natl 1k</field>
<field name="code">31</field>
<field name="cost_price">2.60</field>
<field name="weight">1.000</field>
<field name="international">False</field>
</record>
<record forcecreate="True" id="dp_service_natl_gb_ein" model="delivery.carrier.dp.service">
<field name="name">Großbrief Integral + EINSCHREIBEN</field>
<field name="short_name">Gross Natl EIN</field>
<field name="code">1027</field>
<field name="cost_price">3.95</field>
<field name="weight">0.500</field>
<field name="international">False</field>
</record>
<record forcecreate="True" id="dp_service_natl_mb1k_ein" model="delivery.carrier.dp.service">
<field name="name">Maxibrief Integral + EINSCHREIBEN</field>
<field name="short_name">Maxi Natl 1kg EIN</field>
<field name="code">1037</field>
<field name="cost_price">5.10</field>
<field name="weight">1.000</field>
<field name="international">False</field>
</record>
<record forcecreate="True" id="dp_service_natl_gb_wurf" model="delivery.carrier.dp.service">
<field name="name">Großbrief Integral + EINSCHREIBEN EINWURF</field>
<field name="short_name">Gross Natl WURF</field>
<field name="code">1022</field>
<field name="cost_price">3.60</field>
<field name="weight">0.500</field>
<field name="international">False</field>
</record>
<record forcecreate="True" id="dp_service_natl_mb1k_wurf" model="delivery.carrier.dp.service">
<field name="name">Maxibrief Integral + EINSCHREIBEN EINWURF</field>
<field name="short_name">Maxi Natl 1kg WURF</field>
<field name="code">1032</field>
<field name="cost_price">4.75</field>
<field name="weight">1.000</field>
<field name="international">False</field>
</record>
<record forcecreate="True" id="dp_service_intl_gb_ein" model="delivery.carrier.dp.service">
<field name="name">Großbrief Intern. GK Integral + EINSCHREIBEN</field>
<field name="short_name">Gross Intl EIN</field>
<field name="code">11056</field>
<field name="cost_price">6.20</field>
<field name="weight">0.500</field>
<field name="international">True</field>
</record>
<record forcecreate="True" id="dp_service_intl_mb1k_ein" model="delivery.carrier.dp.service">
<field name="name">Maxibrief Intern. bis 1.000g GK Integral + EINSCHREIBE</field>
<field name="short_name">Maxi Intl 1kg EIN</field>
<field name="code">11076</field>
<field name="cost_price">9.50</field>
<field name="weight">1.000</field>
<field name="international">True</field>
</record>
<record forcecreate="True" id="dp_service_intl_mb2k_ein" model="delivery.carrier.dp.service">
<field name="name">Maxibrief Intern. bis 2.000g GK Integral + EINSCHREIBE</field>
<field name="short_name">Maxi Intl 2kg EIN</field>
<field name="code">11096</field>
<field name="cost_price">19.50</field>
<field name="weight">2.000</field>
<field name="international">True</field>
</record>
</data>
</openerp>

20
data/delivery_demo.xml

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="dp_delivery_carrier" model="delivery.carrier">
<field name="name">Deutsche Post Brief</field>
<field name="normal_price">0</field>
<field name="delivery_type">dp</field>
<!-- partner_id / product_id -->
<field name="dp_service_type" ref=""/>
<field name="environment">test</field>
<field name="extra_service_price">0</field>
<field name="address_validator">False</field>
<field name="genrate_label">True</field>
<field name="void_shipment">False</field>
<field name="uom_id" ref="product.product_uom_kg"/>
<field name="delivery_uom">kg</field>
<field name="image" type="base64" file="dp_delivery_carrier/static/src/img/logo-dp.png"/>
</record>
</data>
</openerp>

98
models/dp_delivery_carrier.py

@ -0,0 +1,98 @@
from openerp import api, fields, models
import logging
from openerp.exceptions import Warning
import pycountry
from inema import Internetmarke
_logger = logging.getLogger(__name__)
TRACKING_URL = 'https://www.deutschepost.de/sendung/simpleQuery.html?locale=en_GB'
# convert from ISO3166 2-digit to 3-digit
def get_alpha3_country_from_alpha2(twodigit):
c = pycountry.countries.get(alpha2=twodigit)
return c.alpha3
# split the last word of a string containing stree name + house number
def split_street_house(streethouse):
r = streethouse.rsplit(' ', 1)
return (r[0], r[1])
def split_first_lastname(name):
r = name.rsplit(' ', 1)
return (r[0], r[1])
class DPDeliveryCarrier(models.Model):
_inherit="delivery.carrier"
def conn_auth_im(self):
config = self._get_config()
partner_id = config['dp_partner_id']
key = config['dp_key']
key_phase = config['dp_key_phase']
pk_user = config['dp_portokasse_user']
pk_passwd = config['dp_portokasse_passwd']
im = Internetmarke(partner_id, key, key_phase)
im.authenticate(pk_user, pk_passwd)
return im
# Convert an Odoo Partner object into Internetmarke Address
def build_im_addr(self, im, partner):
(street, house) = split_street_house(partner.street)
country = get_alpha3_country_from_alpha2(partner.country_id.code)
addr = im.build_addr(street = street,
house = house,
additional = partner.street2,
zipcode = partner.zip,
city = partner.city,
country = country)
if partner.parent_id.name:
return im.build_comp_addr(company = partner.parent_id.name,
address = addr,
person = partner.name)
else:
(first, last) = split_first_lastname(partner.name)
return im.build_pers_addr(first = first,
last = last,
address = addr)
@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
im = self.conn_auth_im()
im_recipient = self.build_im_addr(im, recipient)
im_sender = self.build_im_addr(im, wareohouse)
service = self.sudo().dp_service_type
position = im.build_position(service_type.code, im_sender, im_recipient)
im.add_position(position)
r = im.checkoutPNG()
voucher = r.shoppingCart.voucherList.voucher[0]
filename = 'DP'+voucher.trackId+'.png'
result = { 'exact_price': im.compute_total(),
'weight': service.weight,
'date_delivery': None,
'tracking_number': voucher.trackId,
'voucher_id' : voucher.voucherId,
'order_id' : r.shoppingCart.shopOrderId,
'wallet_balance': r.walletBalance,
'attachments': [(filename, voucher.png_bin)]},
return result
def dp_get_shipping_price_from_so(self, order):
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
return service.cost_price
@api.one
def dp_get_tracking_link(self, pickings):
return TRACKING_URL
@api.one
def dp_cancel_shipment(self, pickings):
raise Warning('Cancelling DP Shipments not supported!')

27
models/dp_shipping_service.py

@ -0,0 +1,27 @@
from openerp import api, fields, models
# extnd delivery.carrier with DP
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')
# New model for DP Products/Services (from ProdWS)
class SMCShippingDpService(models.Model):
_name = "delivery.carrier.dp.service"
name = fields.Char(string="Name", required=1)
short_name = fields.Char(string="Short Name")
code = fields.Integer("Product Code", required=1)
prodws_id = fields.Integer("ProdWS ID")
cost_price = fields.Float("Price", required=1)
weight = fields.Float("Allowed Weight", required=1)
height = fields.Integer("Height")
width = fields.Integer("Width")
length = fields.Integer("Length")
international = fields.Boolean("International", required=1)
# extend stock.picking with fields for Shipment and Voucher ID
class StockPicking(models.Model):
_inerit = "stock.picking"
dp_shipping_number = fields.Char(string="DP Shipment ID")
dp_voucher_number = fields.Char(string="DP Voucher ID")

4
security/ir.model.access.csv

@ -0,0 +1,4 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_dp_service_public_user,delivery.carrier.dp.service,model_delivery_carrier_dp_service,base.group_public,1,0,0,0
access_dp_service_users,delivery.carrier.dp.service,model_delivery_carrier_dp_service,,1,0,0,0
access_dp_service_portal_user,delivery.carrier.dp.service,model_delivery_carrier_dp_service,base.group_portal,1,0,0,0

75
views/dp_delivery_carrier.xml

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_picking_withlabel_form_view" model="ir.ui.view">
<field name="name">delivery.stock.picking_withlabel.form.view</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="odoo_shipping_service_apps.view_picking_withlabel_form_view"/>
<field name="arch" type="xml">
<xpath expr="//label[@for='carrier_tracking_ref']" position="before">
<field name="dp_shipment_number" attrs="{'invisible':[('delivery_type', '!=', 'dp')]}"/>
</xpath>
</field>
</record>
<record id="shipping_dp_form" model="ir.ui.view">
<field name="name">shipping.dp.form</field>
<field name="model">delivery.carrier</field>
<field name="type">form</field>
<field name="inherit_id" ref="odoo_shipping_service_apps.view_delivery_carrier_form_inherit_wk_shipping" />
<field name="arch" type="xml">
<xpath expr="//group[@name='Delivery Setting']" col='2' position="after">
<group string="DP Shipping Infomation " attrs="{'invisible':[('delivery_type', '!=', 'dp')]}">
<field name="dp_service_type" attrs="{'required':[('delivery_type', '==', 'dp')]}" />
</group>
</xpath>
</field>
</record>
<record id="delivery_carrier_dp_service_form" model="ir.ui.view">
<field name="name">delivery.carrier.dp.service.form</field>
<field name="model">delivery.carrier.dp.service</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="name"/>
<field name="short_name"/>
<field name="code"/>
<field name="prodws_id"/>
<field name="international"/>
<field name="cost_price"/>
</group>
<group>
<field name="weight"/>
<field name="height"/>
<field name="width"/>
<field name="length"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="delivery_carrier_dp_service_tree" model="ir.ui.view">
<field name="name">delivery.carrier.dp.service.tree</field>
<field name="model">delivery.carrier.dp.service</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="package">
<field name="name"/>
<field name="short_name"/>
<field name="code"/>
<field name="prodws_id"/>
<field name="cost_price"/>
<field name="weight"/>
<field name="height"/>
<field name="width"/>
<field name="length"/>
<field name="international"/>
</tree>
</field>
</record>
<menuitem id="menu_shipping_dp" name="DP Services" parent="delivery.menu_delivery" string="UPS" />
<menuitem id="menu_shipping_dp_service" parent="menu_shipping_dp" string="Service Type" action="action_delivery_carrier_dp_service"/>
</data>
</openerp>

43
views/res_config.xml

@ -0,0 +1,43 @@
<openerp>
<data>
<record id="view_website_internetmarke_config_setting" model="ir.ui.view">
<field name="name">website.dp.config.settings</field>
<field name="model">website.dp.config.settings</field>
<field name="arch" type="xml">
<form string="Internetmarke Settings" class="oe_form_configuration">
<sheet>
<group string="Internetmarke Credentials">
<field name="dp_partner_id" class="oe_inline"/>
<field name="dp_key" class="oe_inline"/>
<field name="dp_key_phase" class="oe_inline"/>
</group>
<group string="Portokasse Credentials">
<field name="dp_portokasse_user" class="oe_inline"/>
<field name="dp_portokasse_passwd" class="oe_inline"/>
</group>
</sheet>
<footer>
<button string="Apply" type="object" name="execute" class="oe_highlight"/>
<button string="Cancel" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>
<record id="action_module_website_internetmarke_configuration" model="ir.actions.act_window">
<field name="name">Internetmarke Configuration</field>
<field name="res_model">website.dp.config.settings</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<!-- inherit? -->
<record id="internetmarke_configurtaion_installer_todo" model="ir.actions.todo">
<field name="action_id" ref="action_module_website_internetmarke_configuration"/>
<field name="sequence">15</sequence>
<field name="type">automatic</sequence>
</record>
</data>
</openerp>
Loading…
Cancel
Save