[IMP] sale purchase : fix usability
bzr revid: tfr@openerp.com-20101019091103-7pssapvadbyw31wc
This commit is contained in:
parent
7604859423
commit
310e834346
|
@ -501,6 +501,8 @@ class account_voucher(osv.osv):
|
|||
def proforma_voucher(self, cr, uid, ids, context=None):
|
||||
self.action_move_line_create(cr, uid, ids, context=context)
|
||||
return True
|
||||
#return {'type' : 'ir.actions.act_window_close' }
|
||||
|
||||
|
||||
def action_cancel_draft(self, cr, uid, ids, context={}):
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
|
|
|
@ -187,7 +187,7 @@ class purchase_order(osv.osv):
|
|||
help="From Order: a draft invoice will be pre-generated based on the purchase order. The accountant " \
|
||||
"will just have to validate this invoice for control.\n" \
|
||||
"From Picking: a draft invoice will be pre-generated based on validated receptions.\n" \
|
||||
"Manual: no invoice will be pre-generated. The accountant will have to encode manually."
|
||||
"Manual: allows you to generate suppliers invoices by chosing in the uninvoiced lines of all manual purchase orders."
|
||||
),
|
||||
'minimum_planned_date':fields.function(_minimum_planned_date, fnct_inv=_set_minimum_planned_date, method=True,store=True, string='Expected Date', type='date', help="This is computed as the minimum scheduled date of all purchase order lines' products."),
|
||||
'amount_untaxed': fields.function(_amount_all, method=True, digits_compute= dp.get_precision('Purchase Price'), string='Untaxed Amount',
|
||||
|
@ -598,7 +598,7 @@ class purchase_order_line(osv.osv):
|
|||
_columns = {
|
||||
'name': fields.char('Description', size=256, required=True),
|
||||
'product_qty': fields.float('Quantity', required=True, digits=(16,2)),
|
||||
'date_planned': fields.date('Scheduled date', required=True),
|
||||
'date_planned': fields.date('Scheduled Date', required=True),
|
||||
'taxes_id': fields.many2many('account.tax', 'purchase_order_taxe', 'ord_id', 'tax_id', 'Taxes'),
|
||||
'product_uom': fields.many2one('product.uom', 'Product UOM', required=True),
|
||||
'product_id': fields.many2one('product.product', 'Product', domain=[('purchase_ok','=',True)], change_default=True),
|
||||
|
@ -617,7 +617,7 @@ class purchase_order_line(osv.osv):
|
|||
\n* The \'Cancelled\' state is set automatically when user cancel purchase order.'),
|
||||
'invoice_lines': fields.many2many('account.invoice.line', 'purchase_order_line_invoice_rel', 'order_line_id', 'invoice_id', 'Invoice Lines', readonly=True),
|
||||
'invoiced': fields.boolean('Invoiced', readonly=True),
|
||||
'partner_id': fields.related('order_id','partner_id',string='Partner',readonly=True,type="many2one", relation="res.partner"),
|
||||
'partner_id': fields.related('order_id','partner_id',string='Partner',readonly=True,type="many2one", relation="res.partner", store=True),
|
||||
'date_order': fields.related('order_id','date_order',string='Order Date',readonly=True,type="date")
|
||||
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
parent="base.menu_purchase_root" sequence="4"/>
|
||||
<menuitem action="stock.action_picking_tree4" id="menu_action_picking_tree4" parent="menu_procurement_management_inventory"
|
||||
name="Incoming Shipments" sequence="9"
|
||||
groups="base.group_extended"/>
|
||||
groups="base.group_extended"/>
|
||||
<menuitem action="stock.action_reception_picking_move" id="menu_action_picking_tree_in_move"
|
||||
parent="menu_procurement_management_inventory" sequence="11"/>
|
||||
|
||||
|
@ -144,10 +144,10 @@
|
|||
<button name="action_cancel" states="approved,except_picking,except_invoice" string="Cancel Purchase Order" type="object" icon="gtk-cancel"/>
|
||||
<button name="picking_ok" states="except_picking" string="Manually Corrected" icon="gtk-convert"/>
|
||||
<button name="invoice_ok" states="except_invoice" string="Manually Corrected" icon="gtk-convert"/>
|
||||
<button name="purchase_confirm" states="draft" string="Confirm Purchase Order" icon="gtk-go-forward"/>
|
||||
<button name="purchase_confirm" states="draft" string="Convert to Purchase Order" icon="gtk-go-forward"/>
|
||||
<button name="purchase_appbuyer" states="wait_auth" string="Approve Purchase" icon="gtk-ok"/>
|
||||
<button name="purchase_approve" states="confirmed" string="Approved by Supplier" icon="gtk-go-forward"/>
|
||||
<button name="%(report_purchase_order)d" string="Print" states="approved" type="action" icon="gtk-print"/>
|
||||
<button name="%(report_purchase_order)d" string="Print" states="approved" type="action" icon="gtk-print"/>
|
||||
|
||||
</group>
|
||||
</page>
|
||||
|
@ -307,12 +307,16 @@
|
|||
<tree string="Purchase Order Lines">
|
||||
<field name="order_id"/>
|
||||
<field name="name"/>
|
||||
<field name="date_planned" widget="date" width="135"/>
|
||||
<field name="partner_id" string="Supplier" />
|
||||
<field name="product_id"/>
|
||||
<field name="product_qty"/>
|
||||
<field name="product_uom"/>
|
||||
<field name="price_unit"/>
|
||||
<field name="product_qty"/>
|
||||
<field name="product_uom"/>
|
||||
<field name="price_subtotal"/>
|
||||
<field name="date_planned" widget="date" width="135"/>
|
||||
|
||||
|
||||
|
||||
<field name="state" invisible="1"/>
|
||||
<field name="invoiced" invisible="1"/>
|
||||
</tree>
|
||||
|
@ -369,10 +373,12 @@
|
|||
<group>
|
||||
<field name="order_id"/>
|
||||
<field name="product_id"/>
|
||||
</group>
|
||||
<field name="partner_id" string="Supplier"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<group expand="0" string="Group By...">
|
||||
<filter string="Product" icon="terp-gtk-jump-to-rtl" domain="[]" context="{'group_by' : 'product_id'}" />
|
||||
<filter string="Supplier" icon="terp-gtk-jump-to-rtl" domain="[]" context="{'group_by' : 'partner_id'}" />
|
||||
<filter icon="terp-gtk-jump-to-rtl" string="Order Reference" domain="[]" context="{'group_by' :'order_id'}"/>
|
||||
<separator orientation="vertical"/>
|
||||
<filter string="State" icon="terp-stock_effects-object-colorize" domain="[]" context="{'group_by' : 'state'}" />
|
||||
|
@ -401,7 +407,7 @@
|
|||
<field name="name">Purchase Lines Not Invoiced</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">purchase.order.line</field>
|
||||
<field name="domain">[('state','in',('confirmed','done')), ('invoiced','=',False)]</field>
|
||||
<field name="domain">[('state','in',('confirmed','done')), ('invoiced', '=', False)]</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="search_view_id" ref="purchase_order_line_search"/>
|
||||
|
|
|
@ -24,6 +24,7 @@ import ir
|
|||
from osv import osv
|
||||
from tools.translate import _
|
||||
|
||||
|
||||
class purchase_line_invoice(osv.osv_memory):
|
||||
|
||||
""" To create invoice for purchase order line"""
|
||||
|
@ -31,7 +32,8 @@ class purchase_line_invoice(osv.osv_memory):
|
|||
_name = 'purchase.order.line_invoice'
|
||||
_description = 'Purchase Order Line Make Invoice'
|
||||
|
||||
def makeInvoices(self, cr, uid, ids, context):
|
||||
def makeInvoices(self, cr, uid, ids, context=None):
|
||||
|
||||
"""
|
||||
To get Purchase Order line and create Invoice
|
||||
@param self: The object pointer.
|
||||
|
@ -39,7 +41,11 @@ class purchase_line_invoice(osv.osv_memory):
|
|||
@param uid: ID of the user currently logged in
|
||||
@param context: A standard dictionary
|
||||
@return : retrun view of Invoice
|
||||
"""
|
||||
"""
|
||||
|
||||
if context is None:
|
||||
context={}
|
||||
|
||||
record_ids = context.get('active_ids',[])
|
||||
if record_ids:
|
||||
res = False
|
||||
|
@ -49,35 +55,65 @@ class purchase_line_invoice(osv.osv_memory):
|
|||
property_obj=self.pool.get('ir.property')
|
||||
account_fiscal_obj=self.pool.get('account.fiscal.position')
|
||||
invoice_line_obj=self.pool.get('account.invoice.line')
|
||||
|
||||
def make_invoice(order, lines):
|
||||
a = order.partner_id.property_account_payable.id
|
||||
if order.partner_id and order.partner_id.property_payment_term.id:
|
||||
pay_term = order.partner_id.property_payment_term.id
|
||||
|
||||
|
||||
def multiple_order_invoice_name(orders):
|
||||
name = "PO";
|
||||
for order in orders:
|
||||
name += "-%d" % order.id
|
||||
return name
|
||||
|
||||
def multiple_order_invoice_reference(partner, orders):
|
||||
reference = "P%dPO" % partner.id
|
||||
for order in orders:
|
||||
reference += "-%d" % order.id
|
||||
return reference
|
||||
|
||||
def multiple_order_invoice_notes(orders):
|
||||
notes = ""
|
||||
for order in orders:
|
||||
notes += "%s \n" % order.notes
|
||||
return notes
|
||||
|
||||
|
||||
|
||||
def make_invoice_by_partner(partner, orders, lines_ids):
|
||||
"""
|
||||
create a new invoice for one supplier
|
||||
@param partner : The object partner
|
||||
@param orders : The set of orders to add in the invoice
|
||||
@param lines : The list of line's id
|
||||
"""
|
||||
|
||||
a = partner.property_account_payable.id
|
||||
if partner and partner.property_payment_term.id:
|
||||
pay_term = partner.property_payment_term.id
|
||||
else:
|
||||
pay_term = False
|
||||
inv = {
|
||||
'name': order.name,
|
||||
'origin': order.name,
|
||||
'name': multiple_order_invoice_name(orders), #trouver
|
||||
#'origin': order.name, #origin
|
||||
'type': 'in_invoice',
|
||||
'reference': "P%dPO%d" % (order.partner_id.id, order.id),
|
||||
'reference': multiple_order_invoice_reference(partner, orders),
|
||||
'account_id': a,
|
||||
'partner_id': order.partner_id.id,
|
||||
'address_invoice_id': order.partner_address_id.id,
|
||||
'address_contact_id': order.partner_address_id.id,
|
||||
'invoice_line': [(6,0,lines)],
|
||||
'currency_id' : order.pricelist_id.currency_id.id,
|
||||
'comment': order.notes,
|
||||
'partner_id': partner.id,
|
||||
'address_invoice_id': orders[0].partner_address_id.id,
|
||||
'address_contact_id': orders[0].partner_address_id.id,
|
||||
'invoice_line': [(6,0,lines_ids)],
|
||||
'currency_id' : orders[0].pricelist_id.currency_id.id, #currency form the fist ordes
|
||||
'comment': multiple_order_invoice_notes(orders), #concatener les notes
|
||||
'payment_term': pay_term,
|
||||
'fiscal_position': order.partner_id.property_account_position.id
|
||||
'fiscal_position': partner.property_account_position.id
|
||||
}
|
||||
inv_id = invoice_obj.create(cr, uid, inv)
|
||||
return inv_id
|
||||
|
||||
for line in purchase_line_obj.browse(cr,uid,record_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] = []
|
||||
if not line.partner_id.id in invoices:
|
||||
#création des clés
|
||||
print "id of partner %d" % line.partner_id.id
|
||||
invoices[line.partner_id.id] = []
|
||||
if line.product_id:
|
||||
a = line.product_id.product_tmpl_id.property_account_expense.id
|
||||
if not a:
|
||||
|
@ -102,18 +138,22 @@ class purchase_line_invoice(osv.osv_memory):
|
|||
'uos_id': line.product_uom.id,
|
||||
'product_id': line.product_id.id or False,
|
||||
'invoice_line_tax_id': [(6, 0, [x.id for x in line.taxes_id])],
|
||||
'note': line.notes,
|
||||
'note': line.notes,
|
||||
'account_analytic_id': line.account_analytic_id and line.account_analytic_id.id or False,
|
||||
})
|
||||
cr.execute('insert into purchase_order_line_invoice_rel (order_line_id,invoice_id) values (%s,%s)', (line.id, inv_id))
|
||||
purchase_line_obj.write(cr, uid, [line.id], {'invoiced': True})
|
||||
invoices[line.order_id.id].append((line,inv_id))
|
||||
invoices[line.partner_id.id].append((line,inv_id))
|
||||
|
||||
res = []
|
||||
for result in invoices.values():
|
||||
order = result[0][0].order_id
|
||||
#order = result[0][0].order_id
|
||||
il = map(lambda x: x[1], result)
|
||||
res.append(make_invoice(order, il))
|
||||
orders = list(set(map(lambda x : x[0].order_id, result)))
|
||||
|
||||
res.append(make_invoice_by_partner(orders[0].partner_id, orders, il))
|
||||
#debug
|
||||
print res
|
||||
|
||||
return {
|
||||
'domain': "[('id','in', ["+','.join(map(str,res))+"])]",
|
||||
|
|
|
@ -210,7 +210,7 @@
|
|||
<button name="ship_recreate" states="shipping_except" string="Recreate Procurement" icon="gtk-ok"/>
|
||||
<button name="ship_corrected" states="shipping_except" string="Procurement Corrected" icon="gtk-apply"/>
|
||||
<button name="action_cancel" states="manual,progress" string="Cancel Order" type="object" icon="gtk-cancel"/>
|
||||
<button name="manual_invoice" states="manual" string="Create Invoice" icon="gtk-go-forward" type="object"/>
|
||||
<button name="manual_invoice" states="manual" string="Create Final Invoice" icon="gtk-go-forward" type="object"/>
|
||||
<button name="ship_cancel" states="shipping_except" string="Cancel Order" icon="gtk-cancel"/>
|
||||
<button name="action_cancel_draft" states="cancel" string="Set to Draft" type="object" icon="gtk-convert"/>
|
||||
<button name="cancel" states="draft" string="Cancel Order" icon="gtk-cancel"/>
|
||||
|
|
Loading…
Reference in New Issue