[FIX] Make sure we can select dropship on purchase order and see the related customer and invoicing based on shipments works for sale only

[FIX] Sale should lead to invoicing
[IMP] Journal should not depend on picking type code when in dropship

Make sure drop shipment with invoicing on sale orders only, works.
Also the picking type of dropshipping should be incoming.  This
makes it possible to select it on the purchase order.  This also fixes #3421.
And we can create a dropship from a purchase only. (not the good way)
For this, we make the invoicing based on the shipment look at the
purchase related and not on its picking type code as the picking type
of dropshipping is changed back to incoming.
The purchase order will also show the customer address when in
a dropship case.

Closes #3421
This commit is contained in:
Josse Colpaert 2014-12-11 18:32:26 +01:00
parent 0f78618d27
commit 6f8546dfb5
4 changed files with 15 additions and 11 deletions

View File

@ -294,7 +294,8 @@ class purchase_order(osv.osv):
'bid_validity': fields.date('Bid Valid Until', help="Date on which the bid expired"),
'picking_type_id': fields.many2one('stock.picking.type', 'Deliver To', help="This will determine picking type of incoming shipment", required=True,
states={'confirmed': [('readonly', True)], 'approved': [('readonly', True)], 'done': [('readonly', True)]}),
'related_location_id': fields.related('picking_type_id', 'default_location_dest_id', type='many2one', relation='stock.location', string="Related location", store=True),
'related_location_id': fields.related('picking_type_id', 'default_location_dest_id', type='many2one', relation='stock.location', string="Related location", store=True),
'related_usage': fields.related('location_id', 'usage', type='char'),
'shipment_count': fields.function(_count_all, type='integer', string='Incoming Shipments', multi=True),
'invoice_count': fields.function(_count_all, type='integer', string='Invoices', multi=True)
}
@ -380,8 +381,8 @@ class purchase_order(osv.osv):
if picking_type_id:
picktype = self.pool.get("stock.picking.type").browse(cr, uid, picking_type_id, context=context)
if picktype.default_location_dest_id:
value.update({'location_id': picktype.default_location_dest_id.id})
value.update({'related_location_id': picktype.default_location_dest_id and picktype.default_location_dest_id.id or False})
value.update({'location_id': picktype.default_location_dest_id.id, 'related_usage': picktype.default_location_dest_id.usage})
value.update({'related_location_id': picktype.default_location_dest_id.id})
return {'value': value}
def onchange_partner_id(self, cr, uid, ids, partner_id, context=None):
@ -749,7 +750,7 @@ class purchase_order(osv.osv):
'move_dest_id': procurement.move_dest_id.id, #move destination is same as procurement destination
'group_id': procurement.group_id.id or group_id, #move group is same as group of procurements if it exists, otherwise take another group
'procurement_id': procurement.id,
'invoice_state': procurement.rule_id.invoice_state or (procurement.location_id and procurement.location_id.usage == 'customer' and procurement.invoice_state=='picking' and '2binvoiced') or (order.invoice_method == 'picking' and '2binvoiced') or 'none', #dropship case takes from sale
'invoice_state': procurement.rule_id.invoice_state or (procurement.location_id and procurement.location_id.usage == 'customer' and procurement.invoice_state=='2binvoiced' and '2binvoiced') or (order.invoice_method == 'picking' and '2binvoiced') or 'none', #dropship case takes from sale
'propagate': procurement.rule_id.propagate,
})
diff_quantity -= min(procurement_qty, diff_quantity)

View File

@ -226,10 +226,10 @@
<field name="origin" attrs="{'invisible': [('origin','=',False)]}"/>
<field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/>
<field name="picking_type_id" on_change="onchange_picking_type_id(picking_type_id, context)" domain="[('code','=','incoming')]" options="{'no_create': True}" context="{'special_shortened_wh_name': True}" groups="stock.group_locations"/>
<field name="related_location_id" invisible="1"/>
<field name="related_usage" invisible="1"/>
<field name="dest_address_id" string="Customer Address" on_change="onchange_dest_address_id(dest_address_id, context)"
attrs="{'invisible':['|', ('picking_type_id','=',False), ('related_location_id','!=', False)],
'required': [('picking_type_id','!=',False), ('related_location_id','=', False)]}"
attrs="{'invisible':[('related_usage','!=','customer')],
'required': [('related_usage','=', 'customer')]}"
groups="stock.group_locations"/>
</group>
</group>

View File

@ -14,7 +14,7 @@
<record id="picking_type_dropship" model="stock.picking.type">
<field name="name">Dropship</field>
<field name="sequence_id" ref="seq_picking_type_dropship"/>
<field name="code">outgoing</field>
<field name="code">incoming</field>
<field name="default_location_src_id" ref="stock.stock_location_suppliers"/>
<field name="default_location_dest_id" ref="stock.stock_location_customers"/>
</record>

View File

@ -34,9 +34,12 @@ class stock_invoice_onshipping(osv.osv_memory):
pick = pickings and pickings[0]
src_usage = pick.move_lines[0].location_id.usage
dest_usage = pick.move_lines[0].location_dest_id.usage
pick_purchase = pick.move_lines and pick.move_lines[0].purchase_line_id and pick.move_lines[0].purchase_line_id.order_id.invoice_method == 'picking'
if pick.picking_type_id.code == 'outgoing' and src_usage == 'supplier' and dest_usage == 'customer' and pick_purchase:
return 'purchase'
if src_usage == 'supplier' and dest_usage == 'customer':
pick_purchase = pick.move_lines and pick.move_lines[0].purchase_line_id and pick.move_lines[0].purchase_line_id.order_id.invoice_method == 'picking'
if pick_purchase:
return 'purchase'
else:
return 'sale'
else:
return super(stock_invoice_onshipping, self)._get_journal_type(cr, uid, context=context)