[MERGE] sale order & stock improvements

bzr revid: fp@tinyerp.com-20120918172145-lr3vtmm06j7virse
This commit is contained in:
Fabien Pinckaers 2012-09-18 19:21:45 +02:00
commit 5582891098
5 changed files with 49 additions and 70 deletions

View File

@ -145,6 +145,14 @@ class sale_order(osv.osv):
res[sale.id] = 0.0
return res
def _invoice_exists(self, cursor, user, ids, name, arg, context=None):
res = {}
for sale in self.browse(cursor, user, ids, context=context):
res[sale.id] = False
if sale.invoice_ids:
res[sale.id] = True
return res
def _invoiced(self, cursor, user, ids, name, arg, context=None):
res = {}
for sale in self.browse(cursor, user, ids, context=context):
@ -156,7 +164,7 @@ class sale_order(osv.osv):
if invoice.state != 'paid':
res[sale.id] = False
break
if not invoice_existence:
if not invoice_existence or sale.state == 'manual':
res[sale.id] = False
return res
@ -245,6 +253,8 @@ class sale_order(osv.osv):
'invoiced_rate': fields.function(_invoiced_rate, string='Invoiced', type='float'),
'invoiced': fields.function(_invoiced, string='Paid',
fnct_search=_invoiced_search, type='boolean', help="It indicates that an invoice has been paid."),
'invoice_exists': fields.function(_invoice_exists, string='Invoiced',
fnct_search=_invoiced_search, type='boolean', help="It indicates that sale order has at least one invoice."),
'note': fields.text('Terms and conditions'),
'amount_untaxed': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Untaxed Amount',
@ -518,68 +528,45 @@ class sale_order(osv.osv):
This function returns an action that display existing invoices of given sale order ids. It can either be a in a list or in a form view, if there is only one invoice to show.
'''
mod_obj = self.pool.get('ir.model.data')
result = {
'name': _('Cutomer Invoice'),
'view_type': 'form',
'res_model': 'account.invoice',
'context': "{'type':'out_invoice', 'journal_type': 'sale'}",
'type': 'ir.actions.act_window',
'nodestroy': True,
'target': 'current',
}
act_obj = self.pool.get('ir.actions.act_window')
result = mod_obj.get_object_reference(cr, uid, 'account', 'action_invoice_tree1')
id = result and result[1] or False
result = act_obj.read(cr, uid, [id], context=context)[0]
#compute the number of invoices to display
inv_ids = []
for so in self.browse(cr, uid, ids, context=context):
inv_ids += [invoice.id for invoice in so.invoice_ids]
#choose the view_mode accordingly
if len(inv_ids)>1:
res = mod_obj.get_object_reference(cr, uid, 'account', 'invoice_tree')
result.update({
'view_mode': 'tree,form',
'res_id': inv_ids or False
})
result['domain'] = "[('id','in',["+','.join(map(str, inv_ids))+"])]"
else:
res = mod_obj.get_object_reference(cr, uid, 'account', 'invoice_form')
result.update({
'view_mode': 'form',
'res_id': inv_ids and inv_ids[0] or False,
})
result.update(view_id = res and res[1] or False)
result['views'] = [(res and res[1] or False, 'form')]
result['res_id'] = inv_ids and inv_ids[0] or False
return result
def action_view_delivery(self, cr, uid, ids, context=None):
'''
This function returns an action that display existing delivery orders of given sale order ids. It can either be a in a list or in a form view, if there is only one delivery order to show.
'''
mod_obj = self.pool.get('ir.model.data')
result = {
'name': _('Delivery Order'),
'view_type': 'form',
'res_model': 'stock.picking',
'context': "{'type':'out'}",
'type': 'ir.actions.act_window',
'nodestroy': True,
'target': 'current',
}
act_obj = self.pool.get('ir.actions.act_window')
result = mod_obj.get_object_reference(cr, uid, 'stock', 'action_picking_tree')
id = result and result[1] or False
result = act_obj.read(cr, uid, [id], context=context)[0]
#compute the number of delivery orders to display
pick_ids = []
for so in self.browse(cr, uid, ids, context=context):
pick_ids += [picking.id for picking in so.picking_ids]
#choose the view_mode accordingly
if len(pick_ids) > 1:
res = mod_obj.get_object_reference(cr, uid, 'stock', 'view_picking_out_tree')
result.update({
'view_mode': 'tree,form',
'res_id': pick_ids or False
})
result['domain'] = "[('id','in',["+','.join(map(str, pick_ids))+"])]"
else:
res = mod_obj.get_object_reference(cr, uid, 'stock', 'view_picking_out_form')
result.update({
'view_mode': 'form',
'res_id': pick_ids and pick_ids[0] or False,
})
result.update(view_id = res and res[1] or False)
result['views'] = [(res and res[1] or False, 'form')]
result['res_id'] = pick_ids and pick_ids[0] or False
return result
def test_no_product(self, cr, uid, order, context):

View File

@ -163,7 +163,7 @@
<button name="action_button_confirm" states="draft" string="Confirm" type="object"/>
<button name="action_button_confirm" states="sent" string="Confirm" class="oe_highlight" type="object"/>
<button name="action_view_invoice" string="View Invoice" type="object" class="oe_highlight"
attrs="{'invisible': ['|','|',('state', '!=','progress'), ('invoiced', '=', True),('order_policy','=','picking')]}"/>
attrs="{'invisible': [('invoice_exists', '=', False)]}"/>
<button name="action_view_delivery" string="View Delivery Order" type="object" class="oe_highlight"
attrs="{'invisible': ['|','|','|',('picking_ids','=',False),('picking_ids','=',[]), ('state', 'not in', ('progress','manual')),('shipped','=',True)]}"/>
<button name="%(action_view_sale_advance_payment_inv)d" string="Create Invoice"
@ -320,6 +320,7 @@
<group>
<field name="invoiced"/>
<field name="shipped"/>
<field name="invoice_exists" invisible="1"/>
</group>
</group>
</page>

View File

@ -1,5 +1,5 @@
-
I confirm the Quotation with "Deliver & invoice on demand".
I confirm the Quotation with "On Demand" order policy.
-
!workflow {model: sale.order, action: order_confirm, ref: sale_order_2}
-
@ -9,44 +9,34 @@
sale_order = self.browse(cr, uid, ref("sale_order_2"))
assert len(sale_order.invoice_ids) == False, "Invoice should not created."
-
I create advance invoice.
I create advance invoice where type is 'Fixed Price'.
-
!python {model: sale.advance.payment.inv}: |
ctx = context.copy()
ctx.update({"active_model": 'sale.order', "active_ids": [ref("sale_order_2")], "active_id":ref("sale_order_2")})
order_line = self.pool.get('sale.order.line').browse(cr, uid, ref("sale_order_line_4"), context=context)
pay_id = self.create(cr, uid, {'advance_payment_method': 'fixed', 'product_id': order_line.product_id.id, 'amount': order_line.price_subtotal, 'qtty': order_line.product_uom_qty})
pay_id = self.create(cr, uid, {'advance_payment_method': 'fixed', 'product_id': order_line.product_id.id, 'amount': order_line.price_unit})
self.create_invoices(cr, uid, [pay_id], context=ctx)
-
I check Invoice which made advance
I check Invoice which made advance.
-
!python {model: sale.order}: |
order = self.browse(cr, uid, ref('sale_order_2'))
assert order.invoice_ids, "Invoice should be created after make advance invoice."
-
I create Invoice from sale order line.
I create advance invoice where type is 'Invoice all the Sale Order'.
-
!python {model: sale.order.line.make.invoice}: |
!python {model: sale.advance.payment.inv}: |
ctx = context.copy()
ctx.update({"active_model": 'sale.order.line', "active_ids": [ref("sale_order_line_5")], "active_id":ref("sale_order_line_5")})
self.make_invoices(cr, uid, [], context=ctx)
ctx.update({"active_model": 'sale.order', "active_ids": [ref("sale_order_2")], "active_id":ref("sale_order_2")})
pay_id = self.create(cr, uid, {'advance_payment_method': 'all'})
self.create_invoices(cr, uid, [pay_id], context=ctx)
-
I check Invoice which made from sale order line.
I check Invoice which made advance where type is 'Invoice all the Sale Order'.
-
!python {model: sale.order.line}: |
line = self.browse(cr, uid, ref('sale_order_line_5'))
assert line.invoiced, "Line is not invoiced."
assert line.invoice_lines, "Invoice line should be created."
-
I create manual Invoice for order.
-
!record {model: sale.make.invoice, id: sale_make_invoice_1}:
invoice_date: !eval time.strftime('%Y-%m-%d')
-
!python {model: sale.make.invoice}: |
ctx = context.copy()
ctx = ctx.update({"active_model": 'sale.order', "active_ids": [ref("sale_order_2")], "active_id":ref("sale_order_2")})
self.make_invoices(cr, uid, [ref("sale_make_invoice_1")], context)
!python {model: sale.order}: |
order = self.browse(cr, uid, ref('sale_order_2'))
assert order.invoice_ids, "Invoice should be created after make advance invoice where type is 'Invoice all the Sale Order'."
-
I open the Invoice.
-
@ -57,7 +47,7 @@
for invoice in so.invoice_ids:
wf_service.trg_validate(uid, 'account.invoice', invoice.id, 'invoice_open', cr)
-
I pay the invoice
I pay the invoice.
-
!python {model: account.invoice}: |
sale_order = self.pool.get('sale.order')
@ -75,8 +65,9 @@
!python {model: sale.order}: |
sale_order = self.browse(cr, uid, ref("sale_order_2"))
assert sale_order.invoice_ids, "Invoice should be created."
assert sale_order.invoiced, "Order is not invoiced."
assert sale_order.state == 'manual', 'Order should be in Manual.'
assert sale_order.invoice_exists, "Order is not invoiced."
assert sale_order.invoiced, "Order is not paid."
assert sale_order.state == 'progress', 'Order should be in Progress.'
-
I set order policy "Deliver & invoice on demand" as default policy.

View File

@ -910,7 +910,7 @@
<field name="state" nolabel="1" readonly="1" widget="statusbar" statusbar_visible="draft,confirmed,assigned,done" statusbar_colors='{"auto":"blue", "confirmed":"blue"}'/>
</xpath>
<xpath expr="//field[@name='partner_id']" position="replace">
<field name="partner_id" on_change="onchange_partner_in(partner_id)" colspan="4" string="Customer"/>
<field name="partner_id" on_change="onchange_partner_in(partner_id)" string="Customer"/>
</xpath>
<xpath expr="//field[@name='move_lines']" position="replace">
<field name="move_lines" context="{'address_in_id': partner_id, 'picking_type': 'out', 'form_view_ref':'view_move_picking_form', 'tree_view_ref':'view_move_picking_tree'}"/>
@ -1036,7 +1036,7 @@
<button name="action_process" states="assigned" string="Receive" type="object" class="oe_highlight"/>
</xpath>
<xpath expr="//field[@name='partner_id']" position="replace">
<field name="partner_id" on_change="onchange_partner_in(partner_id)" colspan="4" string="Supplier"/>
<field name="partner_id" on_change="onchange_partner_in(partner_id)" string="Supplier"/>
</xpath>
<xpath expr="//field[@name='move_lines']" position="replace">
<field name="move_lines" context="{'address_in_id': partner_id, 'picking_type': 'in', 'form_view_ref':'view_move_picking_form', 'tree_view_ref':'view_move_picking_tree'}"/>

View File

@ -78,7 +78,7 @@ class stock_partial_picking(osv.osv_memory):
if context is None:
context={}
res = super(stock_partial_picking, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
type = context.get('active_model','').split('.')[-1]
type = context.get('default_type', False)
if type:
doc = etree.XML(res['arch'])
for node in doc.xpath("//button[@name='do_partial']"):