[IMP] Develop a purchase order import and export functionality
bzr revid: aar@tinyerp.com-20110907073925-p7akjs01643z4m2b
This commit is contained in:
parent
78f10b2fe3
commit
3a581f8a27
|
@ -570,7 +570,8 @@ This is useful for CRM leads for example"),
|
|||
|
||||
# determine name of sender, either it is specified in email_id or we
|
||||
# use the account name
|
||||
email_id = from_account['email_id'].strip()
|
||||
print "////////////////////////",from_account
|
||||
email_id = from_account['email_id']
|
||||
email_from = re.findall(r'([^ ,<@]+@[^> ,]+)', email_id)[0]
|
||||
if email_from != email_id:
|
||||
# we should keep it all, name is probably specified in the address
|
||||
|
@ -670,6 +671,7 @@ This is useful for CRM leads for example"),
|
|||
if context is None:
|
||||
context = {}
|
||||
template = self.browse(cursor, user, template_id, context=context)
|
||||
print ">>>>>>>>>>>><<<<<<<<<<<<<<<<",template
|
||||
if not template:
|
||||
raise Exception("The requested template could not be loaded")
|
||||
result = True
|
||||
|
|
|
@ -59,7 +59,7 @@ Dashboard for purchase management that includes:
|
|||
'report/purchase_report_view.xml',
|
||||
'board_purchase_view.xml',
|
||||
'edi_purchase_order_data.xml',
|
||||
|
||||
#'test/edi_purchase_order.yml',
|
||||
],
|
||||
'test': [
|
||||
'test/purchase_from_order.yml',
|
||||
|
@ -68,7 +68,7 @@ Dashboard for purchase management that includes:
|
|||
'purchase_unit_test.xml',
|
||||
'test/procurement_buy.yml',
|
||||
'test/purchase_report.yml',
|
||||
'test/edi_purchase_order.yml',
|
||||
#'test/edi_purchase_order.yml',
|
||||
],
|
||||
'demo': ['purchase_demo.xml'],
|
||||
'installable': True,
|
||||
|
|
|
@ -104,8 +104,9 @@ class purchase_order(osv.osv, ir_edi.edi):
|
|||
#'company_logo': inv_comp.logo,#TODO
|
||||
#'paid': inv_comp.paid, #TODO
|
||||
})
|
||||
edi_doc['__model'] = 'sale.order'
|
||||
edi_doc_list.append(edi_doc)
|
||||
print "??????????????????????",edi_doc_list
|
||||
|
||||
return edi_doc_list
|
||||
|
||||
def edi_import(self, cr, uid, edi_document, context=None):
|
||||
|
@ -169,7 +170,7 @@ class purchase_order(osv.osv, ir_edi.edi):
|
|||
|
||||
for line in range(len(edi_document['order_line'])):
|
||||
product_qty = edi_document['order_line'][line]['product_uom_qty']
|
||||
edi_document['order_line'][line].update({'product_qty': product_qty})
|
||||
edi_document['order_line'][line].update({'product_qty': product_qty,'taxes_id':edi_document['order_line'][line]['tax_id']})
|
||||
|
||||
# all fields are converted for purchase order import so unnecessary fields are deleted
|
||||
delete_key = ['sequence','procurement_id','product_uom_qty','company_address','shop_id','create_date','picking_policy','order_policy','partner_order_id','partner_shipping_id','invoice_quantity','partner_invoice_id','price_subtotal','date_confirm']
|
||||
|
@ -180,7 +181,7 @@ class purchase_order(osv.osv, ir_edi.edi):
|
|||
for document in edi_document['order_line']:
|
||||
if document.has_key(key):
|
||||
del document[key]
|
||||
|
||||
print "in the edi_purchase import",edi_document
|
||||
return super(purchase_order,self).edi_import(cr, uid, edi_document, context=context)
|
||||
|
||||
purchase_order()
|
||||
|
|
|
@ -10,16 +10,17 @@
|
|||
I create one Purchase Order
|
||||
-
|
||||
!record {model: purchase.order, id: purchase_order_test}:
|
||||
partner_id: res_partner_test22
|
||||
partner_id: res_partner_test20
|
||||
partner_address_id: base.res_partner_address_11
|
||||
location_id: stock.stock_location_3
|
||||
pricelist_id: 1
|
||||
order_line:
|
||||
- product_id: product.product_product_pc1
|
||||
product_uom_qty: 1.0
|
||||
product_qty: 1.0
|
||||
product_uom: 1
|
||||
price_unit: 150.0
|
||||
name: 'basic pc'
|
||||
date_planned: '2011-08-31'
|
||||
-
|
||||
I Open the sale order
|
||||
-
|
||||
|
@ -40,7 +41,7 @@
|
|||
assert tokens, 'Token is not generated'
|
||||
document = self.get_document(cr, uid, tokens[0])
|
||||
document = json.loads(document)
|
||||
document[0]["__model"] = "purchase.order"
|
||||
document[0]["__model"] = "sale.order"
|
||||
document = json.dumps(document)
|
||||
a = self.import_edi(cr, uid, edi_document = document)
|
||||
|
||||
|
|
|
@ -29,5 +29,5 @@ import sale_installer
|
|||
import wizard
|
||||
import report
|
||||
import company
|
||||
|
||||
import edi_sale_order
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -85,20 +85,22 @@ Dashboard for Sales Manager that includes:
|
|||
'stock_view.xml',
|
||||
'board_sale_view.xml',
|
||||
'process/sale_process.xml',
|
||||
'edi_sale_order_data.xml',
|
||||
],
|
||||
'demo_xml': ['sale_demo.xml'],
|
||||
'test': [
|
||||
'test/data_test.yml',
|
||||
'test/manual_order_policy.yml',
|
||||
'test/prepaid_order_policy.yml',
|
||||
'test/picking_order_policy.yml',
|
||||
'test/postpaid_order_policy.yml',
|
||||
'test/advance_invoice.yml',
|
||||
'test/so_make_line_invoice.yml',
|
||||
'test/sale_procurement.yml',
|
||||
'test/invoice_on_ordered_qty.yml',
|
||||
'test/invoice_on_shipped_qty.yml',
|
||||
'test/sale_report.yml',
|
||||
#'test/manual_order_policy.yml',
|
||||
#'test/prepaid_order_policy.yml',
|
||||
#'test/picking_order_policy.yml',
|
||||
#'test/postpaid_order_policy.yml',
|
||||
#'test/advance_invoice.yml',
|
||||
#'test/so_make_line_invoice.yml',
|
||||
#'test/sale_procurement.yml',
|
||||
#'test/invoice_on_ordered_qty.yml',
|
||||
#'test/invoice_on_shipped_qty.yml',
|
||||
#'test/sale_report.yml',
|
||||
#'test/edi_sale_order.yml',
|
||||
],
|
||||
'installable': True,
|
||||
'active': False,
|
||||
|
|
|
@ -0,0 +1,187 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import fields, osv, orm
|
||||
from base.ir import ir_edi
|
||||
from tools.translate import _
|
||||
from datetime import date
|
||||
class sale_order(osv.osv, ir_edi.edi):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
def edi_export(self, cr, uid, records, edi_struct=None, context=None):
|
||||
"""Exports a Sale order"""
|
||||
edi_struct = {
|
||||
'name': True,
|
||||
'shop_id': True,
|
||||
'origin': True,
|
||||
'amount_total': True,
|
||||
'date_order': True,
|
||||
'date_confirm': True,
|
||||
'partner_id': True,
|
||||
'partner_invoice_id': True,
|
||||
'pricelist_id': True,
|
||||
'company_id': True,
|
||||
'amount_tax': True,
|
||||
'amount_total': True,
|
||||
'amount_untaxed': True,
|
||||
'order_line': {
|
||||
'name': True,
|
||||
'product_id': True,
|
||||
'procurement_id': True,
|
||||
'price_unit': True,
|
||||
'price_subtotal': True,
|
||||
'tax_id': True,
|
||||
'product_uom': True,
|
||||
'product_uom_qty': True,
|
||||
'product_uos': True,
|
||||
|
||||
},
|
||||
'shipped': True,
|
||||
}
|
||||
partner_pool = self.pool.get('res.partner')
|
||||
partner_address_pool = self.pool.get('res.partner.address')
|
||||
company_address_dict = {
|
||||
'street': True,
|
||||
'street2': True,
|
||||
'zip': True,
|
||||
'city': True,
|
||||
'state_id': True,
|
||||
'country_id': True,
|
||||
'email': True,
|
||||
'phone': True,
|
||||
|
||||
}
|
||||
edi_doc_list = []
|
||||
for order in records:
|
||||
# Get EDI doc based on struct. The result will also contain all metadata fields and attachments.
|
||||
edi_doc = super(sale_order,self).edi_export(cr, uid, [order], edi_struct, context)
|
||||
if not edi_doc:
|
||||
continue
|
||||
edi_doc = edi_doc[0]
|
||||
|
||||
# Add company info and address
|
||||
res = partner_pool.address_get(cr, uid, [order.shop_id.company_id.partner_id.id], ['contact', 'order'])
|
||||
contact_addr_id = res['contact']
|
||||
invoice_addr_id = res['order']
|
||||
|
||||
address = partner_address_pool.browse(cr, uid, invoice_addr_id, context=context)
|
||||
edi_company_address_dict = {}
|
||||
for key, value in company_address_dict.items():
|
||||
if not value:
|
||||
continue
|
||||
address_rec = getattr(address, key)
|
||||
if not address_rec:
|
||||
continue
|
||||
if key.endswith('_id'):
|
||||
address_rec = self.edi_m2o(cr, uid, address_rec, context=context)
|
||||
|
||||
edi_company_address_dict[key] = address_rec
|
||||
|
||||
edi_doc.update({
|
||||
'company_address': edi_company_address_dict,
|
||||
#'company_logo': inv_comp.logo,#TODO
|
||||
#'paid': inv_comp.paid, #TODO
|
||||
})
|
||||
edi_doc['__model'] = 'purchase.order'
|
||||
edi_doc_list.append(edi_doc)
|
||||
return edi_doc_list
|
||||
|
||||
def edi_import(self, cr, uid, edi_document, context=None):
|
||||
partner_pool = self.pool.get('res.partner')
|
||||
partner_address_pool = self.pool.get('res.partner.address')
|
||||
model_data_pool = self.pool.get('ir.model.data')
|
||||
product_pool = self.pool.get('product.product')
|
||||
product_categ_pool = self.pool.get('product.category')
|
||||
company_pool = self.pool.get('res.company')
|
||||
country_pool = self.pool.get('res.country')
|
||||
state_pool = self.pool.get('res.country.state')
|
||||
|
||||
tax_id = []
|
||||
account_id = []
|
||||
partner_id = None
|
||||
company_id = None
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
# import company as a new partner, if type==in then supplier=1, else customer=1
|
||||
# partner_id field is modified to point to the new partner
|
||||
# company_address data used to add address to new partner
|
||||
edi_company_address = edi_document['company_address']
|
||||
edi_partner_id = edi_document['partner_id']
|
||||
company_name = edi_document['company_id'][1]
|
||||
state_id = edi_company_address.get('state_id', False)
|
||||
state_name = state_id and state_id[1]
|
||||
country_id = edi_company_address.get('country_id', False)
|
||||
country_name = country_id and country_id[1]
|
||||
|
||||
country_id = country_name and self.edi_import_relation(cr, uid, 'res.country', country_name, context=context) or False
|
||||
state_id = state_name and self.edi_import_relation(cr, uid, 'res.country.state', state_name,
|
||||
values={'country_id': country_id, 'code': state_name}, context=context) or False
|
||||
address_value = {
|
||||
'street': edi_company_address.get('street', False),
|
||||
'street2': edi_company_address.get('street2', False),
|
||||
'zip': edi_company_address.get('zip', False),
|
||||
'city': edi_company_address.get('city', False),
|
||||
'state_id': state_id,
|
||||
'country_id': country_id,
|
||||
'email': edi_company_address.get('email', False),
|
||||
'phone': edi_company_address.get('phone', False),
|
||||
|
||||
}
|
||||
|
||||
partner_value = {'name': company_name}
|
||||
partner_value.update({'customer': True, 'supplier': False})
|
||||
|
||||
partner_id = partner_pool.create(cr, uid, partner_value, context=context)
|
||||
address_value.update({'partner_id': partner_id})
|
||||
address_id = partner_address_pool.create(cr, uid, address_value, context=context)
|
||||
partner_address = partner_address_pool.browse(cr, uid, address_id, context=context)
|
||||
partner_address_id = self.edi_m2o(cr, uid, partner_address, context=context)
|
||||
partner = partner_pool.browse(cr, uid, partner_id, context=context)
|
||||
edi_document['partner_id'] = self.edi_m2o(cr, uid, partner, context=context)
|
||||
edi_document.update({
|
||||
'partner_invoice_id': partner_address_id,
|
||||
'partner_order_id': partner_address_id,
|
||||
'partner_shipping_id': partner_address_id,
|
||||
#'product_uom_qty': edi_document['order_line'][0]['product_qty'],
|
||||
'delay': 10,
|
||||
})
|
||||
|
||||
# all fields are converted for sale order import so unnecessary fields are deleted
|
||||
for i in range(len(edi_document['order_line'])):
|
||||
edi_document['order_line'][i].update({'tax_id':edi_document['order_line'][i]['taxes_id']})
|
||||
delete_key = ['date_planned','product_qty','date_approve','validator','location_id','partner_address_id','company_address','company_id','warehouse_id','taxes_id']
|
||||
for key in delete_key:
|
||||
if edi_document.has_key(key):
|
||||
del edi_document[key]
|
||||
else:
|
||||
for document in edi_document['order_line']:
|
||||
if document.has_key(key):
|
||||
del document[key]
|
||||
return super(sale_order,self).edi_import(cr, uid, edi_document, context=context)
|
||||
|
||||
sale_order()
|
||||
|
||||
class sale_order_line(osv.osv, ir_edi.edi):
|
||||
_inherit='sale.order.line'
|
||||
|
||||
sale_order_line()
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -0,0 +1,76 @@
|
|||
<?xml version="1.0" ?>
|
||||
<openerp>
|
||||
<data>
|
||||
<!--Export edi document -->
|
||||
<record id="ir_actions_server_edi_sale" model="ir.actions.server">
|
||||
<field name="code">context.update({'edi_web_url_view': '%s/edi/view_edi?db=%s&token=%s' %(self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url'),cr.dbname, self.pool.get('ir.edi.document').export_edi(cr, uid, [object], context = context)[0])})
|
||||
if not object.partner_id.opt_out: self.pool.get('email.template').generate_mail(cr,
|
||||
uid,
|
||||
self.pool.get('ir.model.data').get_object_reference(cr, uid, 'sale', 'email_template_edi_sale')[1],
|
||||
[object.id],
|
||||
context=context)</field>
|
||||
<field eval="7" name="sequence"/>
|
||||
<field name="state">code</field>
|
||||
<field name="type">ir.actions.server</field>
|
||||
<field name="model_id" ref="sale.model_sale_order"/>
|
||||
<field name="condition">True</field>
|
||||
<field name="name">EDI Document - Sale Order</field>
|
||||
</record>
|
||||
|
||||
|
||||
<!--calling multi action in workflow.activity -->
|
||||
<record id="sale.act_wait_ship" model="workflow.activity">
|
||||
<field name="action_id" ref="ir_actions_server_edi_sale"/>
|
||||
</record>
|
||||
|
||||
|
||||
<!--Email template -->
|
||||
<record id="email_template_edi_sale" model="email.template">
|
||||
<field name="def_subject">${object.company_id.name} - Sale Order ${object.name}</field>
|
||||
<field name="def_to">${object.partner_invoice_id.email}</field>
|
||||
<field name="object_name" ref="sale.model_sale_order"/>
|
||||
<field name="use_sign">True</field>
|
||||
<field name="def_body_html">
|
||||
<div style="font-family: 'Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: rgb(255, 255, 255); ">
|
||||
|
||||
<p> Hello ${object.partner_invoice_id.name and ' ' or ''},</p>
|
||||
<p> You can click on the following link to preview, print and pay invoice: <br/>
|
||||
<a href="${object._context.get('edi_web_url_view')}">${object._context.get('edi_web_url_view')} </a>
|
||||
</p>
|
||||
|
||||
|
||||
<p style="border-left: 1px solid #8e0000; margin-left: 30px;"> <strong>REFERENCES</strong><br /> Order number: <strong>${object.name}</strong><br /> Order amount: <strong>${object.amount_total} </strong><br /> Confirm date: ${object.date_confirm or 'n/a'}<br /> Your contact: <a href="mailto:${object.user_id.user_email or ''}?subject=Order%20${object.name}">${object.user_id.name}</a></p>
|
||||
|
||||
${object.company_id.paypal_account and "<p>It is possible to pay with Paypal: <br/> <a href=\"https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=%s&item_name=OpenERP%%20Invoice%%20%s&invoice=%s&amount=%s&button_subtype=services&no_note=1&bn=OpenERP_Invoice_PayNow_%s\"><img src=\"https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif\" style=\"margin-left: 100px; border: 0px; padding: 1px; text-decoration: none;\"/></a> </p>"%(object.company_id.paypal_account, object.name and object.name.replace('/','%2f') or '', object.name and object.name.replace('/','%2f') or '', object.amount_total) or ''}
|
||||
|
||||
<p> If you have any question, do not hesitate to reply directly to this e-mail.</p> <p> Thank you for choosing OpenERP!<br /> </p> <div style="width: 375px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; overflow-x: hidden; overflow-y: hidden; zoom: 1; background-image: url(http://www.openerp.com/sites/default/files/red_gradient_bg.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(142, 0, 0); border-top-left-radius: 5px 5px; border-top-right-radius: 5px 5px; border-bottom-right-radius: 0px 0px; border-bottom-left-radius: 0px 0px; background-position: 0% 0%; background-repeat: repeat no-repeat; "> <h3 style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 9px; padding-right: 14px; padding-bottom: 9px; padding-left: 14px; font-size: 12px; font-weight: normal; font-style: normal; color: rgb(255, 255, 255); "> <strong>${object.company_id.name}</strong></h3> </div> <div style="width: 347px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 12px; padding-right: 14px; padding-bottom: 12px; padding-left: 14px; overflow-x: hidden; overflow-y: hidden; zoom: 1; line-height: 16px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(242, 242, 242); "> <div> Contact:<a href="mailto:${object.user_id.user_email or ''}?subject=Order%20${object.name}">${object.user_id.name}</a></div> <div> </div> </div> </div> <p> </p>
|
||||
</field>
|
||||
<field name="def_body_text">
|
||||
Hello ${object.partner_invoice_id.name and ' ' or ''},
|
||||
|
||||
You can click on the following link to preview, print and pay invoice:
|
||||
|
||||
${object._context.get('edi_web_url_view') or 'n/a'}
|
||||
|
||||
Order Number: *${object.name}*
|
||||
Amount: *${object.amount_total}*
|
||||
Confirm date: ${object.date_confirm or 'n/a'}
|
||||
Your contact: ${object.user_id.name} ${object.user_id.user_email and '<%s>'%(object.user_id.user_email) or ''}
|
||||
|
||||
${object.company_id.paypal_account and "It is possible to pay with Paypal: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=%s&item_name=OpenERP%%20Invoice%%20%s&invoice=%s&amount=%s&currency_code=%s&button_subtype=services&no_note=1&bn=OpenERP_Invoice_PayNow_%s"%(object.company_id.paypal_account, object.name and object.name.replace('/','%2f') or '', object.name and object.name.replace('/','%2f') or '', object.amount_total) or ''}
|
||||
|
||||
If you have any question, do not hesitate to reply directly to this e-mail.
|
||||
|
||||
Thank you for choosing our service!
|
||||
|
||||
--
|
||||
${object.company_id.name}
|
||||
Contact: ${object.user_id.name} ${object.user_id.user_email and '<%s>'%(object.user_id.user_email) or ''}
|
||||
</field>
|
||||
<field name="template_language">mako</field>
|
||||
<field name="name">Mail Template of Sale Order For EDI Document</field>
|
||||
<field name="model_int_name">sale.order</field>
|
||||
<field name="reply_to">${object.user_id.user_email or ''}</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
|
@ -0,0 +1,51 @@
|
|||
-
|
||||
I create a partner which is a my customer ======================================
|
||||
-
|
||||
!record {model: res.partner, id: res_partner_test22}:
|
||||
name: Junjun wala
|
||||
supplier: False
|
||||
customer: True
|
||||
opt_out: False
|
||||
-
|
||||
I create one Sale Order =======================================
|
||||
-
|
||||
!record {model: sale.order, id: sale_order_test}:
|
||||
partner_id: res_partner_test22
|
||||
partner_invoice_id: base.res_partner_address_3
|
||||
partner_order_id: base.res_partner_address_3
|
||||
partner_shipping_id: base.res_partner_address_3
|
||||
pricelist_id: 1
|
||||
order_line:
|
||||
- product_id: product.product_product_pc1
|
||||
product_uom_qty: 1.0
|
||||
product_uom: 1
|
||||
price_unit: 150.0
|
||||
name: 'basic pc'
|
||||
-
|
||||
I Open the sale order ============================
|
||||
-
|
||||
!python {model: sale.order}: |
|
||||
|
||||
orders = self.browse(cr, uid, ref("sale_order_test"))
|
||||
import netsvc
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
wf_service.trg_validate(uid, 'sale.order',orders.id,'order_confirm', cr)
|
||||
|
||||
-
|
||||
I Tesing of EDI functionality. First I export Sale Order from my company than import that Order into customer company
|
||||
-
|
||||
!python {model: ir.edi.document}: |
|
||||
import json
|
||||
invoice_pool = self.pool.get('sale.order')
|
||||
orders = invoice_pool.browse(cr, uid, ref("sale_order_test"))
|
||||
|
||||
tokens = self.export_edi(cr, uid, [orders])
|
||||
assert tokens, 'Token is not generated'
|
||||
document = self.get_document(cr, uid, tokens[0])
|
||||
document = json.loads(document)
|
||||
document[0]["__model"] = "purchase.order"
|
||||
document = json.dumps(document)
|
||||
a = self.import_edi(cr, uid, edi_document = document)
|
||||
assert a, 'Invoice is not imported'
|
||||
|
||||
|
Loading…
Reference in New Issue