[IMP]: sale: Converted wizards to osv_memory wizards
bzr revid: rpa@tinyerp.com-20100310085016-ww0jyuowcqib3zdd
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
@@ -15,7 +15,7 @@
|
||||
# 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/>.
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
@@ -45,6 +45,8 @@
|
||||
'depends': ['product', 'stock', 'mrp', 'process'],
|
||||
'init_xml': [],
|
||||
'update_xml': [
|
||||
'wizard/sale_make_invoice_advance.xml',
|
||||
'wizard/sale_line_invoice.xml',
|
||||
'security/sale_security.xml',
|
||||
'security/ir.model.access.csv',
|
||||
'sale_workflow.xml',
|
||||
|
||||
@@ -149,7 +149,12 @@
|
||||
<field name="state" select="2"/>
|
||||
<group col="3" colspan="2">
|
||||
<field name="invoiced" select="2"/>
|
||||
<button colspan="1" name="%(wizard_sale_order_line_invoice)d" states="confirmed" string="Make Invoice" type="action" icon="gtk-print"/>
|
||||
<button colspan="1"
|
||||
name="%(action_view_sale_order_line_make_invoice)d"
|
||||
states="confirmed"
|
||||
string="Make Invoice"
|
||||
type="action"
|
||||
icon="gtk-print" />
|
||||
</group>
|
||||
</page>
|
||||
<page groups="base.group_extended" string="Extra Info">
|
||||
@@ -379,8 +384,14 @@
|
||||
<separator colspan="4" string="States"/>
|
||||
<field name="state" select="2"/>
|
||||
<group col="2" colspan="2">
|
||||
<button name="button_done" states="confirmed,exception" string="Done" type="object" icon="gtk-jump-to"/>
|
||||
<button name="button_cancel" states="confirmed,exception" string="Cancel" type="object" icon="gtk-cancel" />
|
||||
<button name="button_done"
|
||||
states="confirmed,exception"
|
||||
string="Done" type="object"
|
||||
icon="gtk-jump-to" />
|
||||
<button name="button_cancel"
|
||||
states="confirmed,exception"
|
||||
string="Cancel" type="object"
|
||||
icon="gtk-cancel" />
|
||||
</group>
|
||||
</page>
|
||||
<page string="Properties">
|
||||
|
||||
@@ -10,19 +10,19 @@
|
||||
multi="True"
|
||||
string="Make invoices"/>
|
||||
|
||||
<wizard
|
||||
id="wizard_sale_order_line_invoice"
|
||||
keyword="client_action_multi"
|
||||
model="sale.order.line"
|
||||
name="sale.order.line.make_invoice"
|
||||
multi="True"
|
||||
string="Make invoices"/>
|
||||
<!-- <wizard-->
|
||||
<!-- id="wizard_sale_order_line_invoice"-->
|
||||
<!-- keyword="client_action_multi"-->
|
||||
<!-- model="sale.order.line"-->
|
||||
<!-- name="sale.order.line.make_invoice"-->
|
||||
<!-- multi="True"-->
|
||||
<!-- string="Make invoices"/>-->
|
||||
|
||||
<wizard string="Advance Invoice"
|
||||
<!-- <wizard string="Advance Invoice"
|
||||
model="sale.order"
|
||||
name="sale.advance_payment_inv"
|
||||
id="sale.advance_payment"
|
||||
menu="True"/>
|
||||
menu="True"/> -->
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
@@ -15,13 +15,12 @@
|
||||
# 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/>.
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from make_invoice import make_invoice
|
||||
#remaining make_invoice
|
||||
import sale_line_invoice
|
||||
import sale_make_invoice_advance
|
||||
|
||||
import wizard_sale_line_invoice
|
||||
import make_invoice_advance
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
||||
@@ -1,157 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import wizard
|
||||
import pooler
|
||||
from osv import fields, osv
|
||||
from tools.translate import _
|
||||
|
||||
form = """<?xml version="1.0"?>
|
||||
<form string="Advance Payment">
|
||||
<field name="product_id"/>
|
||||
<newline />
|
||||
<field name="qtty"/>
|
||||
<field name="amount"/>
|
||||
<newline />
|
||||
</form>
|
||||
"""
|
||||
fields = {
|
||||
'product_id': {'string':'Product', 'type':'many2one','relation':'product.product','required':True},
|
||||
'amount': {'string':'Unit Price', 'type':'float', 'size':(16,2),'required':True},
|
||||
'qtty': {'string':'Quantity', 'type':'float', 'size':(16,2),'required':True, 'default': lambda *a: 1},
|
||||
}
|
||||
|
||||
form_msg = """<?xml version="1.0"?>
|
||||
<form string="Invoices">
|
||||
<label string="You invoice has been successfully created !"/>
|
||||
</form>
|
||||
"""
|
||||
fields_msg = {}
|
||||
|
||||
def _createInvoices(self, cr, uid, data, context={}):
|
||||
list_inv = []
|
||||
pool_obj = pooler.get_pool(cr.dbname)
|
||||
obj_sale = pool_obj.get('sale.order')
|
||||
data_sale = obj_sale.browse(cr,uid,data['ids'])
|
||||
obj_lines = pool_obj.get('account.invoice.line')
|
||||
for sale in data_sale:
|
||||
address_contact = False
|
||||
address_invoice = False
|
||||
create_ids = []
|
||||
ids_inv = []
|
||||
if sale.order_policy == 'postpaid':
|
||||
raise osv.except_osv(
|
||||
_('Error'),
|
||||
_("You cannot make an advance on a sale order that is defined as 'Automatic Invoice after delivery'."))
|
||||
val = obj_lines.product_id_change(cr, uid, [], data['form']['product_id'],uom = False, partner_id = sale.partner_id.id, fposition_id=sale.fiscal_position.id)
|
||||
line_id =obj_lines.create(cr, uid, {
|
||||
'name': val['value']['name'],
|
||||
'account_id':val['value']['account_id'],
|
||||
'price_unit': data['form']['amount'],
|
||||
'quantity': data['form']['qtty'],
|
||||
'discount': False,
|
||||
'uos_id': val['value']['uos_id'],
|
||||
'product_id':data['form']['product_id'],
|
||||
'invoice_line_tax_id': [(6,0,val['value']['invoice_line_tax_id'])],
|
||||
'account_analytic_id': sale.project_id and sale.project_id.id or False,
|
||||
'note':'',
|
||||
})
|
||||
create_ids.append(line_id)
|
||||
inv = {
|
||||
'name': sale.name,
|
||||
'origin': sale.name,
|
||||
'type': 'out_invoice',
|
||||
'reference': False,
|
||||
'account_id': sale.partner_id.property_account_receivable.id,
|
||||
'partner_id': sale.partner_id.id,
|
||||
'address_invoice_id':sale.partner_invoice_id.id,
|
||||
'address_contact_id':sale.partner_order_id.id,
|
||||
'invoice_line': [(6,0,create_ids)],
|
||||
'currency_id' :sale.pricelist_id.currency_id.id,
|
||||
'comment': '',
|
||||
'payment_term':sale.payment_term.id,
|
||||
'fiscal_position': sale.partner_id.property_account_position.id
|
||||
}
|
||||
inv_obj = pool_obj.get('account.invoice')
|
||||
inv_id = inv_obj.create(cr, uid, inv)
|
||||
|
||||
for inv in sale.invoice_ids:
|
||||
ids_inv.append(inv.id)
|
||||
ids_inv.append(inv_id)
|
||||
obj_sale.write(cr,uid,sale.id,{'invoice_ids':[(6,0,ids_inv)]})
|
||||
list_inv.append(inv_id)
|
||||
#
|
||||
# If invoice on picking: add the cost on the SO
|
||||
# If not, the advance will be deduced when generating the final invoice
|
||||
#
|
||||
if sale.order_policy=='picking':
|
||||
pool_obj.get('sale.order.line').create(cr, uid, {
|
||||
'order_id': sale.id,
|
||||
'name': val['value']['name'],
|
||||
'price_unit': -data['form']['amount'],
|
||||
'product_uom_qty': data['form']['qtty'],
|
||||
'product_uos_qty': data['form']['qtty'],
|
||||
'product_uos': val['value']['uos_id'],
|
||||
'product_uom': val['value']['uos_id'],
|
||||
'product_id':data['form']['product_id'],
|
||||
'discount': False,
|
||||
'tax_id': [(6,0,val['value']['invoice_line_tax_id'])],
|
||||
}, context)
|
||||
return {'invoice_ids':list_inv}
|
||||
|
||||
class sale_advance_payment(wizard.interface):
|
||||
def _open_invoice(self, cr, uid, data, context):
|
||||
pool_obj = pooler.get_pool(cr.dbname)
|
||||
mod_obj = pool_obj.get('ir.model.data')
|
||||
result = mod_obj._get_id(cr, uid, 'account', 'view_account_invoice_filter')
|
||||
id = mod_obj.read(cr, uid, result, ['res_id'])
|
||||
model_data_ids = pool_obj.get('ir.model.data').search(cr,uid,[('model','=','ir.ui.view'),('name','=','invoice_form')])
|
||||
resource_id = pool_obj.get('ir.model.data').read(cr,uid,model_data_ids,fields=['res_id'])[0]['res_id']
|
||||
return {
|
||||
'domain': "[('id','in', ["+','.join(map(str,data['form']['invoice_ids']))+"])]",
|
||||
'name': 'Invoices',
|
||||
'view_type': 'form',
|
||||
'view_mode': 'tree,form',
|
||||
'res_model': 'account.invoice',
|
||||
'views': [(False,'tree'),(resource_id,'form')],
|
||||
'context': "{'type':'out_invoice'}",
|
||||
'type': 'ir.actions.act_window',
|
||||
'search_view_id': id['res_id']
|
||||
}
|
||||
|
||||
states = {
|
||||
'init' : {
|
||||
'actions' : [],
|
||||
'result' : {'type' : 'form' , 'arch' : form,'fields' : fields,'state' : [('end','Cancel','gtk-cancel'),('create','Create Advance Invoice','gtk-ok')]}
|
||||
},
|
||||
'create': {
|
||||
'actions': [_createInvoices],
|
||||
'result': {'type' : 'form' ,'arch' : form_msg,'fields' : fields_msg, 'state':[('end','Close','gtk-close'),('open','Open Advance Invoice','gtk-open')]}
|
||||
},
|
||||
'open': {
|
||||
'actions': [],
|
||||
'result': {'type':'action', 'action':_open_invoice, 'state':'end'}
|
||||
}
|
||||
}
|
||||
|
||||
sale_advance_payment("sale.advance_payment_inv")
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 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
|
||||
from service import web_services
|
||||
import wizard
|
||||
import netsvc
|
||||
import ir
|
||||
import pooler
|
||||
|
||||
class sale_order_line_make_invoice(osv.osv_memory):
|
||||
_name = "sale.order.line.make.invoice"
|
||||
_description = "Sale OrderLine Make_invoice"
|
||||
_columns = {
|
||||
'grouped': fields.boolean('Group the invoices'),
|
||||
}
|
||||
_default = {
|
||||
'grouped' : lambda *a: False
|
||||
}
|
||||
|
||||
def makeInvoices(self, cr, uid, ids, context):
|
||||
res = False
|
||||
invoices = {}
|
||||
|
||||
#TODO: merge with sale.py/make_invoice
|
||||
def make_invoice(order, lines):
|
||||
a = order.partner_id.property_account_receivable.id
|
||||
if order.partner_id and order.partner_id.property_payment_term.id:
|
||||
pay_term = order.partner_id.property_payment_term.id
|
||||
else:
|
||||
pay_term = False
|
||||
inv = {
|
||||
'name': order.name,
|
||||
'origin': order.name,
|
||||
'type': 'out_invoice',
|
||||
'reference': "P%dSO%d" % (order.partner_id.id, order.id),
|
||||
'account_id': a,
|
||||
'partner_id': order.partner_id.id,
|
||||
'address_invoice_id': order.partner_invoice_id.id,
|
||||
'address_contact_id': order.partner_invoice_id.id,
|
||||
'invoice_line': [(6,0,lines)],
|
||||
'currency_id' : order.pricelist_id.currency_id.id,
|
||||
'comment': order.note,
|
||||
'payment_term': pay_term,
|
||||
'fiscal_position': order.partner_id.property_account_position.id
|
||||
}
|
||||
inv_id = self.pool.get('account.invoice').create(cr, uid, inv)
|
||||
return inv_id
|
||||
|
||||
for line in self.pool.get('sale.order.line').browse(cr,uid,context['active_ids']):
|
||||
if (not line.invoiced) and (line.state not in ('draft','cancel')):
|
||||
if not line.order_id.id in invoices:
|
||||
invoices[line.order_id.id] = []
|
||||
line_id = self.pool.get('sale.order.line').invoice_line_create(cr, uid,
|
||||
[line.id])
|
||||
for lid in line_id:
|
||||
invoices[line.order_id.id].append((line, lid))
|
||||
self.pool.get('sale.order.line').write(cr, uid, [line.id],
|
||||
{'invoiced': True})
|
||||
flag = True
|
||||
data_sale = self.pool.get('sale.order').browse(cr,uid,line.order_id.id)
|
||||
for line in data_sale.order_line:
|
||||
if not line.invoiced:
|
||||
flag = False
|
||||
break
|
||||
if flag:
|
||||
wf_service = netsvc.LocalService('workflow')
|
||||
wf_service.trg_validate(uid, 'sale.order', line.order_id.id, 'all_lines', cr)
|
||||
self.pool.get('sale.order').write(cr,uid,[line.order_id.id],{'state' : 'progress'})
|
||||
|
||||
for result in invoices.values():
|
||||
order = result[0][0].order_id
|
||||
il = map(lambda x: x[1], result)
|
||||
res = make_invoice(order, il)
|
||||
cr.execute('INSERT INTO sale_order_invoice_rel \
|
||||
(order_id,invoice_id) values (%s,%s)', (order.id, res))
|
||||
return {}
|
||||
|
||||
|
||||
sale_order_line_make_invoice()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="view_sale_order_line_make_invoice" model="ir.ui.view">
|
||||
<field name="name">Sale OrderLine Make Invoice</field>
|
||||
<field name="model">sale.order.line.make.invoice</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Create invoices">
|
||||
<separator colspan="4" string="Do you really want to create the invoices ?" />
|
||||
<field name="grouped" />
|
||||
<separator string="" colspan="6" />
|
||||
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
|
||||
<button name="makeInvoices" string="Create Invoices" type="object" icon="gtk-ok"/>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_view_sale_order_line_make_invoice" model="ir.actions.act_window">
|
||||
<field name="name">Make Invoices</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">sale.order.line.make.invoice</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="context">{'record_id' : active_id}</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.values" id="sale_make_invoice">
|
||||
<field name="model_id" ref="sale.model_sale_order_line" />
|
||||
<field name="object" eval="1" />
|
||||
<field name="name">Make Invoices</field>
|
||||
<field name="key2">client_action_multi</field>
|
||||
<field name="value" eval="'ir.actions.act_window,' + str(ref('action_view_sale_order_line_make_invoice'))" />
|
||||
<field name="key">action</field>
|
||||
<field name="model">sale.order.line</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -0,0 +1,154 @@
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 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
|
||||
from service import web_services
|
||||
from tools.translate import _
|
||||
import ir
|
||||
import netsvc
|
||||
import pooler
|
||||
import wizard
|
||||
|
||||
|
||||
class sale_advance_payment_inv(osv.osv_memory):
|
||||
_name = "sale.advance.payment.inv"
|
||||
_description = "Sale Advance Payment Invoice"
|
||||
_columns = {
|
||||
'product_id': fields.many2one('product.product', 'Product', required=True),
|
||||
'amount': fields.float('Unit Price', size=(16, 2), required=True),
|
||||
'qtty': fields.float('Quantity', size=(16, 2), required=True),
|
||||
}
|
||||
_default = {
|
||||
'qtty' : lambda *a: 1
|
||||
}
|
||||
def createInvoices(self, cr, uid, ids, context={}):
|
||||
list_inv = []
|
||||
obj_sale = self.pool.get('sale.order')
|
||||
obj_lines = self.pool.get('account.invoice.line')
|
||||
for sale_adv_obj in self.browse(cr, uid, ids):
|
||||
for sale in obj_sale.browse(cr, uid, context['active_ids']):
|
||||
address_contact = False
|
||||
address_invoice = False
|
||||
create_ids = []
|
||||
ids_inv = []
|
||||
if sale.order_policy == 'postpaid':
|
||||
raise osv.except_osv(
|
||||
_('Error'),
|
||||
_("You cannot make an advance on a sale order \
|
||||
that is defined as 'Automatic Invoice after delivery'."))
|
||||
val = obj_lines.product_id_change(cr, uid, [], sale_adv_obj.product_id.id,
|
||||
uom = False, partner_id = sale.partner_id.id, fposition_id=sale.fiscal_position.id)
|
||||
line_id =obj_lines.create(cr, uid, {
|
||||
'name': val['value']['name'],
|
||||
'account_id': val['value']['account_id'],
|
||||
'price_unit': sale_adv_obj.amount,
|
||||
'quantity': sale_adv_obj.qtty,
|
||||
'discount': False,
|
||||
'uos_id': val['value']['uos_id'],
|
||||
'product_id': sale_adv_obj.product_id.id,
|
||||
'invoice_line_tax_id': [(6, 0, val['value']['invoice_line_tax_id'])],
|
||||
'account_analytic_id': sale.project_id.id or False,
|
||||
#'note':'',
|
||||
})
|
||||
create_ids.append(line_id)
|
||||
inv = {
|
||||
'name': sale.name,
|
||||
'origin': sale.name,
|
||||
'type': 'out_invoice',
|
||||
'reference': False,
|
||||
'account_id': sale.partner_id.property_account_receivable.id,
|
||||
'partner_id': sale.partner_id.id,
|
||||
'address_invoice_id':sale.partner_invoice_id.id,
|
||||
'address_contact_id':sale.partner_order_id.id,
|
||||
'invoice_line': [(6, 0, create_ids)],
|
||||
'currency_id' :sale.pricelist_id.currency_id.id,
|
||||
'comment': '',
|
||||
'payment_term':sale.payment_term.id,
|
||||
'fiscal_position': sale.partner_id.property_account_position.id
|
||||
}
|
||||
inv_obj = self.pool.get('account.invoice')
|
||||
inv_id = inv_obj.create(cr, uid, inv)
|
||||
|
||||
for inv in sale.invoice_ids:
|
||||
ids_inv.append(inv.id)
|
||||
ids_inv.append(inv_id)
|
||||
obj_sale.write(cr, uid, sale.id, {'invoice_ids':[(6, 0, ids_inv)]})
|
||||
list_inv.append(inv_id)
|
||||
#
|
||||
# If invoice on picking: add the cost on the SO
|
||||
# If not, the advance will be deduced when generating the final invoice
|
||||
#
|
||||
if sale.order_policy=='picking':
|
||||
self.pool.get('sale.order.line').create(cr, uid, {
|
||||
'order_id': sale.id,
|
||||
'name': val['value']['name'],
|
||||
'price_unit': -sale_adv_obj.amount,
|
||||
'product_uom_qty': sale_adv_obj.qtty,
|
||||
'product_uos_qty': sale_adv_obj.qtty,
|
||||
'product_uos': val['value']['uos_id'],
|
||||
'product_uom': val['value']['uos_id'],
|
||||
'product_id': sale_adv_obj.product_id.id,
|
||||
'discount': False,
|
||||
'tax_id': [(6, 0, val['value']['invoice_line_tax_id'])],
|
||||
}, context)
|
||||
|
||||
return {#'invoice_ids':list_inv,
|
||||
'name': 'Open Invoice',
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'sale.open.invoice',
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
'context': "{'invoice_ids'=%s}" % (list_inv)
|
||||
}
|
||||
|
||||
sale_advance_payment_inv()
|
||||
|
||||
class sale_open_invoice(osv.osv_memory):
|
||||
_name = "sale.open.invoice"
|
||||
_description = "Sale Open Invoice"
|
||||
_columns = {
|
||||
}
|
||||
|
||||
def open_invoice(self, cr, uid, ids, context):
|
||||
mod_obj = self.pool.get('ir.model.data')
|
||||
invoices = []
|
||||
#TODO: Can not get invoice ids here
|
||||
for advance_pay in self.browse(cr, uid, ids):
|
||||
result = mod_obj._get_id(cr, uid, 'account', 'view_account_invoice_filter')
|
||||
id = mod_obj.read(cr, uid, result, ['res_id'])
|
||||
model_data_ids = self.pool.get('ir.model.data').search(cr, uid,
|
||||
[('model', '=', 'ir.ui.view'), ('name', '=', 'invoice_form')])
|
||||
resource_id = self.pool.get('ir.model.data').read(cr, uid, model_data_ids,
|
||||
fields=['res_id'])[0]['res_id']
|
||||
return {
|
||||
# 'domain': "[('id','in', ["+','.join(map(str, invoices))+"])]", # TODO
|
||||
'name': 'Invoices',
|
||||
'view_type': 'form',
|
||||
'view_mode': 'tree,form',
|
||||
'res_model': 'account.invoice',
|
||||
'views': [(False, 'tree'), (resource_id, 'form')],
|
||||
'context': "{'type':'out_invoice'}",
|
||||
'type': 'ir.actions.act_window',
|
||||
'search_view_id': id['res_id']
|
||||
}
|
||||
sale_open_invoice()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -0,0 +1,70 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="view_sale_advance_payment_inv" model="ir.ui.view">
|
||||
<field name="name">Sale Advance Payment Invoive</field>
|
||||
<field name="model">sale.advance.payment.inv</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Advance Payment">
|
||||
<field name="product_id"/>
|
||||
<newline />
|
||||
<field name="qtty"/>
|
||||
<field name="amount"/>
|
||||
<newline />
|
||||
<separator string="" colspan="4"/>
|
||||
<label string="" colspan="2" />
|
||||
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
|
||||
<button name="createInvoices" string="Create Advance Invoice" type="object" icon="gtk-ok"/>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_view_sale_advance_payment_inv" model="ir.actions.act_window">
|
||||
<field name="name">Advance Invoice</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">sale.advance.payment.inv</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="context">{'record_id' : active_id}</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.values" id="sale_advance_payment_inv1">
|
||||
<field name="model_id" ref="sale.model_sale_order" />
|
||||
<field name="object" eval="1" />
|
||||
<field name="name">Advance Invoice</field>
|
||||
<field name="key2">client_action_multi</field>
|
||||
<field name="value" eval="'ir.actions.act_window,' + str(ref('action_view_sale_advance_payment_inv'))" />
|
||||
<field name="key">action</field>
|
||||
<field name="model">sale.order</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="view_sale_open_invoice" model="ir.ui.view">
|
||||
<field name="name">Open Invoice</field>
|
||||
<field name="model">sale.open.invoice</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Invoices">
|
||||
<label string="You invoice has been successfully created!" />
|
||||
<newline />
|
||||
<separator string="" colspan="4"/>
|
||||
<group colspan="4">
|
||||
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
|
||||
<button name="open_invoice" string="Open Invoice" type="object" icon="gtk-open"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_view_sale_open_invoice" model="ir.actions.act_window">
|
||||
<field name="name">Open Invoice</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">sale.open.invoice</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -1,121 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import wizard
|
||||
import netsvc
|
||||
import ir
|
||||
import pooler
|
||||
|
||||
invoice_form = """<?xml version="1.0"?>
|
||||
<form string="Create invoices">
|
||||
<separator colspan="4" string="Do you really want to create the invoices ?" />
|
||||
<field name="grouped" />
|
||||
</form>
|
||||
"""
|
||||
|
||||
invoice_fields = {
|
||||
'grouped' : {'string':'Group the invoices', 'type':'boolean', 'default': lambda *a: False}
|
||||
}
|
||||
|
||||
def _makeInvoices(self, cr, uid, data, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
res = False
|
||||
invoices = {}
|
||||
|
||||
#TODO: merge with sale.py/make_invoice
|
||||
def make_invoice(order, lines):
|
||||
a = order.partner_id.property_account_receivable.id
|
||||
if order.partner_id and order.partner_id.property_payment_term.id:
|
||||
pay_term = order.partner_id.property_payment_term.id
|
||||
else:
|
||||
pay_term = False
|
||||
inv = {
|
||||
'name': order.name,
|
||||
'origin': order.name,
|
||||
'type': 'out_invoice',
|
||||
'reference': "P%dSO%d" % (order.partner_id.id, order.id),
|
||||
'account_id': a,
|
||||
'partner_id': order.partner_id.id,
|
||||
'address_invoice_id': order.partner_invoice_id.id,
|
||||
'address_contact_id': order.partner_invoice_id.id,
|
||||
'invoice_line': [(6,0,lines)],
|
||||
'currency_id' : order.pricelist_id.currency_id.id,
|
||||
'comment': order.note,
|
||||
'payment_term': pay_term,
|
||||
'fiscal_position': order.partner_id.property_account_position.id
|
||||
}
|
||||
inv_id = pool.get('account.invoice').create(cr, uid, inv)
|
||||
return inv_id
|
||||
|
||||
for line in pool.get('sale.order.line').browse(cr,uid,data['ids']):
|
||||
if (not line.invoiced) and (line.state not in ('draft','cancel')):
|
||||
if not line.order_id.id in invoices:
|
||||
invoices[line.order_id.id] = []
|
||||
line_id = pool.get('sale.order.line').invoice_line_create(cr, uid,
|
||||
[line.id])
|
||||
for lid in line_id:
|
||||
invoices[line.order_id.id].append((line, lid))
|
||||
pool.get('sale.order.line').write(cr, uid, [line.id],
|
||||
{'invoiced': True})
|
||||
flag = True
|
||||
data_sale = pool.get('sale.order').browse(cr,uid,line.order_id.id)
|
||||
for line in data_sale.order_line:
|
||||
if not line.invoiced:
|
||||
flag = False
|
||||
break
|
||||
if flag:
|
||||
wf_service = netsvc.LocalService('workflow')
|
||||
wf_service.trg_validate(uid, 'sale.order', line.order_id.id, 'all_lines', cr)
|
||||
pool.get('sale.order').write(cr,uid,[line.order_id.id],{'state' : 'progress'})
|
||||
|
||||
for result in invoices.values():
|
||||
order = result[0][0].order_id
|
||||
il = map(lambda x: x[1], result)
|
||||
res = make_invoice(order, il)
|
||||
cr.execute('INSERT INTO sale_order_invoice_rel \
|
||||
(order_id,invoice_id) values (%s,%s)', (order.id, res))
|
||||
return {}
|
||||
|
||||
|
||||
class line_make_invoice(wizard.interface):
|
||||
states = {
|
||||
'init' : {
|
||||
'actions': [],
|
||||
'result': {
|
||||
'type': 'form',
|
||||
'arch': invoice_form,
|
||||
'fields': invoice_fields,
|
||||
'state': [
|
||||
('end', 'Cancel'),
|
||||
('invoice', 'Create invoices')
|
||||
]
|
||||
}
|
||||
},
|
||||
'invoice' : {
|
||||
'actions' : [_makeInvoices],
|
||||
'result' : {'type': 'state', 'state': 'end'}
|
||||
},
|
||||
}
|
||||
|
||||
line_make_invoice("sale.order.line.make_invoice")
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
Reference in New Issue
Block a user