[IMP] Inter-company pricing: put price on move when only partner and not connected to sale or purchase + invoice_state inverse function
This commit is contained in:
parent
8b204e6751
commit
a0d855ffad
|
@ -727,7 +727,7 @@ class purchase_order(osv.osv):
|
||||||
'origin': order.name,
|
'origin': order.name,
|
||||||
'route_ids': order.picking_type_id.warehouse_id and [(6, 0, [x.id for x in order.picking_type_id.warehouse_id.route_ids])] or [],
|
'route_ids': order.picking_type_id.warehouse_id and [(6, 0, [x.id for x in order.picking_type_id.warehouse_id.route_ids])] or [],
|
||||||
'warehouse_id':order.picking_type_id.warehouse_id.id,
|
'warehouse_id':order.picking_type_id.warehouse_id.id,
|
||||||
'invoice_state': order.invoice_method == 'picking' and '2binvoiced' or 'none'
|
'invoice_state': order.invoice_method == 'picking' and '2binvoiced' or 'none',
|
||||||
}
|
}
|
||||||
|
|
||||||
diff_quantity = order_line.product_qty
|
diff_quantity = order_line.product_qty
|
||||||
|
|
|
@ -53,7 +53,6 @@ class stock_move(osv.osv):
|
||||||
default['purchase_line_id'] = False
|
default['purchase_line_id'] = False
|
||||||
return super(stock_move, self).copy(cr, uid, id, default, context)
|
return super(stock_move, self).copy(cr, uid, id, default, context)
|
||||||
|
|
||||||
|
|
||||||
def _create_invoice_line_from_vals(self, cr, uid, move, invoice_line_vals, context=None):
|
def _create_invoice_line_from_vals(self, cr, uid, move, invoice_line_vals, context=None):
|
||||||
invoice_line_id = super(stock_move, self)._create_invoice_line_from_vals(cr, uid, move, invoice_line_vals, context=context)
|
invoice_line_id = super(stock_move, self)._create_invoice_line_from_vals(cr, uid, move, invoice_line_vals, context=context)
|
||||||
if move.purchase_line_id:
|
if move.purchase_line_id:
|
||||||
|
@ -69,7 +68,7 @@ class stock_move(osv.osv):
|
||||||
def _get_master_data(self, cr, uid, move, company, context=None):
|
def _get_master_data(self, cr, uid, move, company, context=None):
|
||||||
if move.purchase_line_id:
|
if move.purchase_line_id:
|
||||||
purchase_order = move.purchase_line_id.order_id
|
purchase_order = move.purchase_line_id.order_id
|
||||||
return purchase_order.partner_id, purchase_order.create_uid.id, purchase_order.pricelist_id.currency_id.id
|
return purchase_order.partner_id, purchase_order.create_uid.id, purchase_order.currency_id.id
|
||||||
return super(stock_move, self)._get_master_data(cr, uid, move, company, context=context)
|
return super(stock_move, self)._get_master_data(cr, uid, move, company, context=context)
|
||||||
|
|
||||||
def _get_invoice_line_vals(self, cr, uid, move, partner, inv_type, context=None):
|
def _get_invoice_line_vals(self, cr, uid, move, partner, inv_type, context=None):
|
||||||
|
|
|
@ -1525,12 +1525,6 @@ class stock_move(osv.osv):
|
||||||
res.append((line.id, name))
|
res.append((line.id, name))
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def create(self, cr, uid, vals, context=None):
|
|
||||||
if vals.get('product_id') and not vals.get('price_unit'):
|
|
||||||
prod_obj = self.pool.get('product.product')
|
|
||||||
vals['price_unit'] = prod_obj.browse(cr, uid, vals['product_id'], context=context).standard_price
|
|
||||||
return super(stock_move, self).create(cr, uid, vals, context=context)
|
|
||||||
|
|
||||||
def _quantity_normalize(self, cr, uid, ids, name, args, context=None):
|
def _quantity_normalize(self, cr, uid, ids, name, args, context=None):
|
||||||
uom_obj = self.pool.get('product.uom')
|
uom_obj = self.pool.get('product.uom')
|
||||||
res = {}
|
res = {}
|
||||||
|
@ -2020,6 +2014,26 @@ class stock_move(osv.osv):
|
||||||
date_expected = time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
|
date_expected = time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
|
||||||
return {'value': {'date': date_expected}}
|
return {'value': {'date': date_expected}}
|
||||||
|
|
||||||
|
def attribute_price(self, cr, uid, move, context=None):
|
||||||
|
"""
|
||||||
|
Attribute price to move, important in multi-company
|
||||||
|
"""
|
||||||
|
if move.location_id.usage != 'internal' and move.location_dest_id.usage == 'internal' and not move.price_unit:
|
||||||
|
partner = move.partner_id or (move.picking_id and move.picking_id.partner_id)
|
||||||
|
price = False
|
||||||
|
# If partner given, search price in its purchase pricelist
|
||||||
|
if partner and partner.property_product_pricelist_purchase:
|
||||||
|
pricelist_obj = self.pool.get("product.pricelist")
|
||||||
|
pricelist = partner.property_product_pricelist.id
|
||||||
|
price = pricelist_obj.price_get(cr, uid, [pricelist],
|
||||||
|
move.product_id.id, move.product_uom_qty, partner, {
|
||||||
|
'uom': move.product_uom.id,
|
||||||
|
'date': move.date,
|
||||||
|
})[pricelist]
|
||||||
|
if not price:
|
||||||
|
price = move.product_id.standard_price
|
||||||
|
self.write(cr, uid, [move.id], {'price_unit': price})
|
||||||
|
|
||||||
|
|
||||||
def action_confirm(self, cr, uid, ids, context=None):
|
def action_confirm(self, cr, uid, ids, context=None):
|
||||||
""" Confirms stock move or put it in waiting if it's linked to another move.
|
""" Confirms stock move or put it in waiting if it's linked to another move.
|
||||||
|
@ -2033,6 +2047,7 @@ class stock_move(osv.osv):
|
||||||
}
|
}
|
||||||
to_assign = {}
|
to_assign = {}
|
||||||
for move in self.browse(cr, uid, ids, context=context):
|
for move in self.browse(cr, uid, ids, context=context):
|
||||||
|
self.attribute_price(cr, uid, move, context=context)
|
||||||
state = 'confirmed'
|
state = 'confirmed'
|
||||||
#if the move is preceeded, then it's waiting (if preceeding move is done, then action_assign has been called already and its state is already available)
|
#if the move is preceeded, then it's waiting (if preceeding move is done, then action_assign has been called already and its state is already available)
|
||||||
if move.move_orig_ids:
|
if move.move_orig_ids:
|
||||||
|
|
|
@ -96,7 +96,13 @@ class stock_move(osv.osv):
|
||||||
|
|
||||||
def _get_master_data(self, cr, uid, move, company, context=None):
|
def _get_master_data(self, cr, uid, move, company, context=None):
|
||||||
''' returns a tuple (browse_record(res.partner), ID(res.users), ID(res.currency)'''
|
''' returns a tuple (browse_record(res.partner), ID(res.users), ID(res.currency)'''
|
||||||
return move.picking_id.partner_id, uid, company.currency_id.id
|
currency = company.currency_id.id
|
||||||
|
if move.partner_id:
|
||||||
|
if move.partner_id.property_product_pricelist_purchase and move.location_id.usage != 'internal' and move.location_dest_id.usage == 'internal':
|
||||||
|
currency = move.partner_id.property_product_pricelist_purchase.currency_id.id
|
||||||
|
elif move.partner_id.property_product_pricelist and move.location_id.usage == 'internal' and move.location_dest_id.usage != 'internal':
|
||||||
|
currency = move.partner_id.property_product_pricelist.currency_id.id
|
||||||
|
return move.picking_id.partner_id, uid, currency
|
||||||
|
|
||||||
def _create_invoice_line_from_vals(self, cr, uid, move, invoice_line_vals, context=None):
|
def _create_invoice_line_from_vals(self, cr, uid, move, invoice_line_vals, context=None):
|
||||||
return self.pool.get('account.invoice.line').create(cr, uid, invoice_line_vals, context=context)
|
return self.pool.get('account.invoice.line').create(cr, uid, invoice_line_vals, context=context)
|
||||||
|
@ -110,10 +116,26 @@ class stock_move(osv.osv):
|
||||||
if context is None:
|
if context is None:
|
||||||
context = {}
|
context = {}
|
||||||
if type in ('in_invoice', 'in_refund'):
|
if type in ('in_invoice', 'in_refund'):
|
||||||
# Take the user company and pricetype
|
if move_line.partner_id:
|
||||||
product = move_line.product_id.with_context(currency_id=move_line.company_id.currency_id.id)
|
return move_line.price_unit
|
||||||
amount_unit = product.price_get('standard_price')[move_line.product_id.id]
|
else:
|
||||||
return amount_unit
|
# Take the user company and pricetype
|
||||||
|
# TODO: This intercompany still needed?
|
||||||
|
product = move_line.product_id.with_context(currency_id=move_line.company_id.currency_id.id)
|
||||||
|
amount_unit = product.price_get('standard_price')[move_line.product_id.id]
|
||||||
|
return amount_unit
|
||||||
|
else:
|
||||||
|
# If partner given, search price in its sale pricelist
|
||||||
|
if move_line.partner_id and move_line.partner_id.property_product_pricelist:
|
||||||
|
pricelist_obj = self.pool.get("product.pricelist")
|
||||||
|
pricelist = move_line.partner_id.property_product_pricelist.id
|
||||||
|
price = pricelist_obj.price_get(cr, uid, [pricelist],
|
||||||
|
product, move_line.product_uom_qty, move_line.partner_id.id, {
|
||||||
|
'uom': move_line.product_uom.id,
|
||||||
|
'date': move_line.date,
|
||||||
|
})[pricelist]
|
||||||
|
if price:
|
||||||
|
return price
|
||||||
return move_line.product_id.list_price
|
return move_line.product_id.list_price
|
||||||
|
|
||||||
def _get_invoice_line_vals(self, cr, uid, move, partner, inv_type, context=None):
|
def _get_invoice_line_vals(self, cr, uid, move, partner, inv_type, context=None):
|
||||||
|
@ -172,13 +194,20 @@ class stock_picking(osv.osv):
|
||||||
res.append(move.picking_id.id)
|
res.append(move.picking_id.id)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def _set_inv_state(self, cr, uid, picking_id, name, value, arg, context=None):
|
||||||
|
pick = self.browse(cr, uid, picking_id, context=context)
|
||||||
|
moves = [x.id for x in pick.move_lines]
|
||||||
|
move_obj= self.pool.get("stock.move")
|
||||||
|
move_obj.write(cr, uid, moves, {'invoice_state': pick.invoice_state})
|
||||||
|
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
'invoice_state': fields.function(__get_invoice_state, type='selection', selection=[
|
'invoice_state': fields.function(__get_invoice_state, type='selection', selection=[
|
||||||
("invoiced", "Invoiced"),
|
("invoiced", "Invoiced"),
|
||||||
("2binvoiced", "To Be Invoiced"),
|
("2binvoiced", "To Be Invoiced"),
|
||||||
("none", "Not Applicable")
|
("none", "Not Applicable")
|
||||||
], string="Invoice Control", required=True,
|
], string="Invoice Control", required=True,
|
||||||
|
fnct_inv = _set_inv_state,
|
||||||
store={
|
store={
|
||||||
'stock.picking': (lambda self, cr, uid, ids, c={}: ids, ['state'], 10),
|
'stock.picking': (lambda self, cr, uid, ids, c={}: ids, ['state'], 10),
|
||||||
'stock.move': (__get_picking_move, ['picking_id', 'invoice_state'], 10),
|
'stock.move': (__get_picking_move, ['picking_id', 'invoice_state'], 10),
|
||||||
|
|
Loading…
Reference in New Issue