[IMP]:Adding stock picking in edi

bzr revid: han@tinyerp.com-20110708093022-qm22kull5wq1vvmi
This commit is contained in:
Hardik Ansodariy (OpenERP)
2011-07-08 15:00:22 +05:30
parent c0520f35cc
commit d1ce89e2a5
5 changed files with 195 additions and 11 deletions
+2 -2
View File
@@ -122,14 +122,14 @@ module named account_voucher.
'board_account_view.xml',
"wizard/account_report_profit_loss_view.xml",
"wizard/account_report_balance_sheet_view.xml",
#"edi_invoice_action.xml",
],
'demo_xml': [
'account_demo.xml',
'project/project_demo.xml',
'project/analytic_account_demo.xml',
'demo/account_minimal.xml',
"edi_invoice_action.xml",
#"edi_invoice_action.xml",
# 'account_unit_test.xml',
],
'test': [
+5 -6
View File
@@ -3,7 +3,7 @@
<data>
<!--Export edi document -->
<record id="ir_actions_server_invoice" model="ir.actions.server">
<field name="code">context.update({'token':self.pool.get('ir.edi.document').export_edi(cr, uid, [object], context = context)})</field>
<field name="code">context.update({'token':self.pool.get('ir.edi.document').export_edi(cr, uid, [object], context = context),'invoice':object.number,'company':object.company_id.name,'currency':object.currency_id.name,'amount':object.amount_total,'date_due':object.date_due})</field>
<field eval="6" name="sequence"/>
<field name="state">code</field>
<field name="type">ir.actions.server</field>
@@ -49,15 +49,14 @@
<field name="def_body_html"></field>
<field name="object_name" ref="account.model_account_invoice"/>
<field name="def_cc">xyz</field>
<field name="def_body_text">test ${object._context.get('token')}
${object.account_id.currency_mode}
<field name="def_body_text">
Hello,
We just registered the invoice 'INV/001' for 121 EUR for your company 'ASUSTek'.
We just registered the invoice ${object.number} for ${object.amount}, ${object.currency} for your company ${object.company}.
You can click on the following link to preview, print and pay this invoice:
http://URL_ON_WEB_CLIENT
http://localhost:8080/openerp/token? ${object._context.get('token')}
Please note that this invoice has to be paid before 12/04/2011.
Please note that this invoice has to be paid before ${object.date_due}
Regards,</field>
<field name="template_language">mako</field>
+2 -1
View File
@@ -24,5 +24,6 @@ import partner
import product
import report
import wizard
import edi_stock_picking
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+3 -2
View File
@@ -48,7 +48,7 @@ Thanks to the double entry management, the inventory controlling is powerful and
"depends" : ["product", "account"],
"category" : "Warehouse",
"init_xml" : [],
"demo_xml" : ["stock_demo.xml"],
#"demo_xml" : ["stock_demo.xml"],
"update_xml" : [
"security/stock_security.xml",
"security/ir.model.access.csv",
@@ -75,7 +75,8 @@ Thanks to the double entry management, the inventory controlling is powerful and
"partner_view.xml",
"report/report_stock_move_view.xml",
"report/report_stock_view.xml",
"board_warehouse_view.xml"
"board_warehouse_view.xml",
"test/edi_stock_picking.yml",
],
'test': ['test/stock_test.yml',
'test/stock_report.yml',
+183
View File
@@ -0,0 +1,183 @@
# -*- 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 _
class stock_picking(osv.osv, ir_edi.edi):
_inherit = 'stock.picking'
def edi_export(self, cr, uid, records, edi_struct=None, context=None):
"""Exports a supplier or customer invoice"""
edi_struct = {
'origin': True,
'type': True,
'stock_journal_id': True,
'move_type': True,
'date': True,
'date_done': True,
'move_lines': {
'name': True,
'date': True,
'date_expected': True,
'product_id': True,
'product_qty': True,
'product_uom': True,
'location_id': True,
'location_dest_id': True,
'company_id': True,
},
'invoice_state': True,
'address_id': True,
'company_id': 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 picking in records:
# Get EDI doc based on struct. The result will also contain all metadata fields and attachments.
edi_doc = super(stock_picking,self).edi_export(cr, uid, [picking], 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, [picking.company_id.partner_id.id], ['contact', 'picking'])
contact_addr_id = res['contact']
invoice_addr_id = res['picking']
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_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')
account_journal_pool = self.pool.get('account.journal')
invoice_line_pool = self.pool.get('account.invoice.line')
account_pool = self.pool.get('account.account')
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']
company_name = edi_document['company_id'][1]
shipping_type = edi_document['type']
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_id = partner_pool.search(cr, uid, [('name','=',company_name)])
if len(partner_id):
partner_id = partner_pool.browse(cr, uid, partner_id[0], context=context)
address_id = partner_id.address[0].id
else:
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)
edi_document.update({'address_id': self.edi_m2o(cr, uid, partner_address, context=context)})
# change type: out'<->'in for shipping
shipping_type = shipping_type.startswith('in') and shipping_type.replace('in','out') or shipping_type.replace('out','in')
edi_document['type'] = shipping_type
company_id = edi_document['company_id']
#print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",edi_document['move_lines']
edi_document.update({'company_id': edi_document['move_lines'][0]['company_id']})
edi_document['move_lines'][0].update({'company_id':company_id})
del edi_document['company_address']
return super(stock_picking,self).edi_import(cr, uid, edi_document, context=context)
stock_picking()
class stock_move(osv.osv, ir_edi.edi):
_inherit='stock.move'
stock_move()