本文整理汇总了Python中odoo.tools.float_utils.float_is_zero函数的典型用法代码示例。如果您正苦于以下问题:Python float_is_zero函数的具体用法?Python float_is_zero怎么用?Python float_is_zero使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了float_is_zero函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _update_reserved_quantity
def _update_reserved_quantity(self, product_id, location_id, quantity, lot_id=None, package_id=None, owner_id=None, strict=False):
""" Increase the reserved quantity, i.e. increase `reserved_quantity` for the set of quants
sharing the combination of `product_id, location_id` if `strict` is set to False or sharing
the *exact same characteristics* otherwise. Typically, this method is called when reserving
a move or updating a reserved move line. When reserving a chained move, the strict flag
should be enabled (to reserve exactly what was brought). When the move is MTS,it could take
anything from the stock, so we disable the flag. When editing a move line, we naturally
enable the flag, to reflect the reservation according to the edition.
:return: a list of tuples (quant, quantity_reserved) showing on which quant the reservation
was done and how much the system was able to reserve on it
"""
self = self.sudo()
rounding = product_id.uom_id.rounding
quants = self._gather(product_id, location_id, lot_id=lot_id, package_id=package_id, owner_id=owner_id, strict=strict)
reserved_quants = []
if float_compare(quantity, 0, precision_rounding=rounding) > 0:
# if we want to reserve
available_quantity = self._get_available_quantity(product_id, location_id, lot_id=lot_id, package_id=package_id, owner_id=owner_id, strict=strict)
if float_compare(quantity, available_quantity, precision_rounding=rounding) > 0:
raise UserError(_('It is not possible to reserve more products of %s than you have in stock.') % product_id.display_name)
elif float_compare(quantity, 0, precision_rounding=rounding) < 0:
# if we want to unreserve
available_quantity = sum(quants.mapped('reserved_quantity'))
if float_compare(abs(quantity), available_quantity, precision_rounding=rounding) > 0:
raise UserError(_('It is not possible to unreserve more products of %s than you have in stock.') % product_id.display_name)
else:
return reserved_quants
for quant in quants:
if float_compare(quantity, 0, precision_rounding=rounding) > 0:
max_quantity_on_quant = quant.quantity - quant.reserved_quantity
if float_compare(max_quantity_on_quant, 0, precision_rounding=rounding) <= 0:
continue
max_quantity_on_quant = min(max_quantity_on_quant, quantity)
quant.reserved_quantity += max_quantity_on_quant
reserved_quants.append((quant, max_quantity_on_quant))
quantity -= max_quantity_on_quant
available_quantity -= max_quantity_on_quant
else:
max_quantity_on_quant = min(quant.reserved_quantity, abs(quantity))
quant.reserved_quantity -= max_quantity_on_quant
reserved_quants.append((quant, -max_quantity_on_quant))
quantity += max_quantity_on_quant
available_quantity += max_quantity_on_quant
if float_is_zero(quantity, precision_rounding=rounding) or float_is_zero(available_quantity, precision_rounding=rounding):
break
return reserved_quants
开发者ID:datenbetrieb,项目名称:odoo,代码行数:50,代码来源:stock_quant.py
示例2: _auto_balance_opening_move
def _auto_balance_opening_move(self):
""" Checks the opening_move of this company. If it has not been posted yet
and is unbalanced, balances it with a automatic account.move.line in the
current year earnings account.
"""
if self.account_opening_move_id and self.account_opening_move_id.state == 'draft':
debit_diff, credit_diff = self.get_opening_move_differences(self.account_opening_move_id.line_ids)
currency = self.currency_id
balancing_move_line = self.account_opening_move_id.line_ids.filtered(lambda x: x.account_id == self.get_unaffected_earnings_account())
if float_is_zero(debit_diff + credit_diff, precision_rounding=currency.rounding):
if balancing_move_line:
# zero difference and existing line : delete the line
balancing_move_line.unlink()
else:
if balancing_move_line:
# Non-zero difference and existing line : edit the line
balancing_move_line.write({'debit': credit_diff, 'credit': debit_diff})
else:
# Non-zero difference and no existing line : create a new line
balancing_account = self.get_unaffected_earnings_account()
self.env['account.move.line'].create({
'name': _('Automatic Balancing Line'),
'move_id': self.account_opening_move_id.id,
'account_id': balancing_account.id,
'debit': credit_diff,
'credit': debit_diff,
})
开发者ID:ovnicraft,项目名称:odoo,代码行数:29,代码来源:company.py
示例3: _update_available_quantity
def _update_available_quantity(self, product_id, location_id, quantity, lot_id=None, package_id=None, owner_id=None, in_date=None):
""" Increase or decrease `reserved_quantity` of a set of quants for a given set of
product_id/location_id/lot_id/package_id/owner_id.
:param product_id:
:param location_id:
:param quantity:
:param lot_id:
:param package_id:
:param owner_id:
:param datetime in_date: Should only be passed when calls to this method are done in
order to move a quant. When creating a tracked quant, the
current datetime will be used.
:return: tuple (available_quantity, in_date as a datetime)
"""
self = self.sudo()
quants = self._gather(product_id, location_id, lot_id=lot_id, package_id=package_id, owner_id=owner_id, strict=True)
rounding = product_id.uom_id.rounding
if lot_id:
incoming_dates = quants.mapped('in_date') # `mapped` already filtered out falsy items
incoming_dates = [fields.Datetime.from_string(incoming_date) for incoming_date in incoming_dates]
if in_date:
incoming_dates += [in_date]
# If multiple incoming dates are available for a given lot_id/package_id/owner_id, we
# consider only the oldest one as being relevant.
if incoming_dates:
in_date = fields.Datetime.to_string(min(incoming_dates))
else:
in_date = fields.Datetime.now()
for quant in quants:
try:
with self._cr.savepoint():
self._cr.execute("SELECT 1 FROM stock_quant WHERE id = %s FOR UPDATE NOWAIT", [quant.id], log_exceptions=False)
quant.write({
'quantity': quant.quantity + quantity,
'in_date': in_date,
})
# cleanup empty quants
if float_is_zero(quant.quantity, precision_rounding=rounding) and float_is_zero(quant.reserved_quantity, precision_rounding=rounding):
quant.unlink()
break
except OperationalError as e:
if e.pgcode == '55P03': # could not obtain the lock
continue
else:
raise
else:
self.create({
'product_id': product_id.id,
'location_id': location_id.id,
'quantity': quantity,
'lot_id': lot_id and lot_id.id,
'package_id': package_id and package_id.id,
'owner_id': owner_id and owner_id.id,
'in_date': in_date,
})
return self._get_available_quantity(product_id, location_id, lot_id=lot_id, package_id=package_id, owner_id=owner_id, strict=False, allow_negative=True), fields.Datetime.from_string(in_date)
开发者ID:jeremiahyan,项目名称:odoo,代码行数:59,代码来源:stock_quant.py
示例4: _free_reservation
def _free_reservation(self, product_id, location_id, quantity, lot_id=None, package_id=None, owner_id=None, ml_to_ignore=None):
""" When editing a done move line or validating one with some forced quantities, it is
possible to impact quants that were not reserved. It is therefore necessary to edit or
unlink the move lines that reserved a quantity now unavailable.
:param ml_to_ignore: recordset of `stock.move.line` that should NOT be unreserved
"""
self.ensure_one()
if ml_to_ignore is None:
ml_to_ignore = self.env['stock.move.line']
ml_to_ignore |= self
# Check the available quantity, with the `strict` kw set to `True`. If the available
# quantity is greather than the quantity now unavailable, there is nothing to do.
available_quantity = self.env['stock.quant']._get_available_quantity(
product_id, location_id, lot_id=lot_id, package_id=package_id, owner_id=owner_id, strict=True
)
if quantity > available_quantity:
# We now have to find the move lines that reserved our now unavailable quantity. We
# take care to exclude ourselves and the move lines were work had already been done.
oudated_move_lines_domain = [
('move_id.state', 'not in', ['done', 'cancel']),
('product_id', '=', product_id.id),
('lot_id', '=', lot_id.id if lot_id else False),
('location_id', '=', location_id.id),
('owner_id', '=', owner_id.id if owner_id else False),
('package_id', '=', package_id.id if package_id else False),
('product_qty', '>', 0.0),
('id', 'not in', ml_to_ignore.ids),
]
oudated_candidates = self.env['stock.move.line'].search(oudated_move_lines_domain)
# As the move's state is not computed over the move lines, we'll have to manually
# recompute the moves which we adapted their lines.
move_to_recompute_state = self.env['stock.move']
rounding = self.product_uom_id.rounding
for candidate in oudated_candidates:
if float_compare(candidate.product_qty, quantity, precision_rounding=rounding) <= 0:
quantity -= candidate.product_qty
move_to_recompute_state |= candidate.move_id
if candidate.qty_done:
candidate.product_uom_qty = 0.0
else:
candidate.unlink()
if float_is_zero(quantity, precision_rounding=rounding):
break
else:
# split this move line and assign the new part to our extra move
quantity_split = float_round(
candidate.product_qty - quantity,
precision_rounding=self.product_uom_id.rounding,
rounding_method='UP')
candidate.product_uom_qty = self.product_id.uom_id._compute_quantity(quantity_split, candidate.product_uom_id, rounding_method='HALF-UP')
move_to_recompute_state |= candidate.move_id
break
move_to_recompute_state._recompute_state()
开发者ID:Vauxoo,项目名称:odoo,代码行数:58,代码来源:stock_move_line.py
示例5: check_reserved_done_quantity
def check_reserved_done_quantity(self):
for move_line in self:
if move_line.state == 'done' and not float_is_zero(move_line.product_uom_qty, precision_digits=self.env['decimal.precision'].precision_get('Product Unit of Measure')):
raise ValidationError(_('A done move line should never have a reserved quantity.'))
开发者ID:rmoorman,项目名称:odoo,代码行数:4,代码来源:stock_move_line.py
示例6: unlink
def unlink(self):
precision = self.env['decimal.precision'].precision_get('Product Unit of Measure')
for ml in self:
if ml.state in ('done', 'cancel'):
raise UserError(_('You can not delete product moves if the picking is done. You can only correct the done quantities.'))
# Unlinking a move line should unreserve.
if ml.product_id.type == 'product' and not ml.location_id.should_bypass_reservation() and not float_is_zero(ml.product_qty, precision_digits=precision):
try:
self.env['stock.quant']._update_reserved_quantity(ml.product_id, ml.location_id, -ml.product_qty, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id, strict=True)
except UserError:
if ml.lot_id:
self.env['stock.quant']._update_reserved_quantity(ml.product_id, ml.location_id, -ml.product_qty, lot_id=False, package_id=ml.package_id, owner_id=ml.owner_id, strict=True)
else:
raise
moves = self.mapped('move_id')
res = super(StockMoveLine, self).unlink()
if moves:
moves._recompute_state()
return res
开发者ID:rmoorman,项目名称:odoo,代码行数:19,代码来源:stock_move_line.py
示例7: write
def write(self, vals):
""" Through the interface, we allow users to change the charateristics of a move line. If a
quantity has been reserved for this move line, we impact the reservation directly to free
the old quants and allocate the new ones.
"""
if self.env.context.get('bypass_reservation_update'):
return super(StockMoveLine, self).write(vals)
Quant = self.env['stock.quant']
precision = self.env['decimal.precision'].precision_get('Product Unit of Measure')
# We forbid to change the reserved quantity in the interace, but it is needed in the
# case of stock.move's split.
# TODO Move me in the update
if 'product_uom_qty' in vals:
for ml in self.filtered(lambda m: m.state in ('partially_available', 'assigned') and m.product_id.type == 'product'):
if not ml.location_id.should_bypass_reservation():
qty_to_decrease = ml.product_qty - ml.product_uom_id._compute_quantity(vals['product_uom_qty'], ml.product_id.uom_id, rounding_method='HALF-UP')
try:
Quant._update_reserved_quantity(ml.product_id, ml.location_id, -qty_to_decrease, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id, strict=True)
except UserError:
if ml.lot_id:
Quant._update_reserved_quantity(ml.product_id, ml.location_id, -qty_to_decrease, lot_id=False, package_id=ml.package_id, owner_id=ml.owner_id, strict=True)
else:
raise
triggers = [
('location_id', 'stock.location'),
('location_dest_id', 'stock.location'),
('lot_id', 'stock.production.lot'),
('package_id', 'stock.quant.package'),
('result_package_id', 'stock.quant.package'),
('owner_id', 'res.partner')
]
updates = {}
for key, model in triggers:
if key in vals:
updates[key] = self.env[model].browse(vals[key])
if updates:
for ml in self.filtered(lambda ml: ml.state in ['partially_available', 'assigned'] and ml.product_id.type == 'product'):
if not ml.location_id.should_bypass_reservation():
try:
Quant._update_reserved_quantity(ml.product_id, ml.location_id, -ml.product_qty, lot_id=ml.lot_id, package_id=ml.package_id, owner_id=ml.owner_id, strict=True)
except UserError:
if ml.lot_id:
Quant._update_reserved_quantity(ml.product_id, ml.location_id, -ml.product_qty, lot_id=False, package_id=ml.package_id, owner_id=ml.owner_id, strict=True)
else:
raise
if not updates.get('location_id', ml.location_id).should_bypass_reservation():
new_product_qty = 0
try:
q = Quant._update_reserved_quantity(ml.product_id, updates.get('location_id', ml.location_id), ml.product_qty, lot_id=updates.get('lot_id', ml.lot_id),
package_id=updates.get('package_id', ml.package_id), owner_id=updates.get('owner_id', ml.owner_id), strict=True)
new_product_qty = sum([x[1] for x in q])
except UserError:
if updates.get('lot_id'):
# If we were not able to reserve on tracked quants, we can use untracked ones.
try:
q = Quant._update_reserved_quantity(ml.product_id, updates.get('location_id', ml.location_id), ml.product_qty, lot_id=False,
package_id=updates.get('package_id', ml.package_id), owner_id=updates.get('owner_id', ml.owner_id), strict=True)
new_product_qty = sum([x[1] for x in q])
except UserError:
pass
if new_product_qty != ml.product_qty:
new_product_uom_qty = self.product_id.uom_id._compute_quantity(new_product_qty, self.product_uom_id, rounding_method='HALF-UP')
ml.with_context(bypass_reservation_update=True).product_uom_qty = new_product_uom_qty
# When editing a done move line, the reserved availability of a potential chained move is impacted. Take care of running again `_action_assign` on the concerned moves.
next_moves = self.env['stock.move']
if updates or 'qty_done' in vals:
for ml in self.filtered(lambda ml: ml.move_id.state == 'done' and ml.product_id.type == 'product'):
# undo the original move line
qty_done_orig = ml.move_id.product_uom._compute_quantity(ml.qty_done, ml.move_id.product_id.uom_id, rounding_method='HALF-UP')
in_date = Quant._update_available_quantity(ml.product_id, ml.location_dest_id, -qty_done_orig, lot_id=ml.lot_id,
package_id=ml.result_package_id, owner_id=ml.owner_id)[1]
Quant._update_available_quantity(ml.product_id, ml.location_id, qty_done_orig, lot_id=ml.lot_id,
package_id=ml.package_id, owner_id=ml.owner_id, in_date=in_date)
# move what's been actually done
product_id = ml.product_id
location_id = updates.get('location_id', ml.location_id)
location_dest_id = updates.get('location_dest_id', ml.location_dest_id)
qty_done = vals.get('qty_done', ml.qty_done)
lot_id = updates.get('lot_id', ml.lot_id)
package_id = updates.get('package_id', ml.package_id)
result_package_id = updates.get('result_package_id', ml.result_package_id)
owner_id = updates.get('owner_id', ml.owner_id)
quantity = ml.move_id.product_uom._compute_quantity(qty_done, ml.move_id.product_id.uom_id, rounding_method='HALF-UP')
if not location_id.should_bypass_reservation():
ml._free_reservation(product_id, location_id, quantity, lot_id=lot_id, package_id=package_id, owner_id=owner_id)
if not float_is_zero(quantity, precision_digits=precision):
available_qty, in_date = Quant._update_available_quantity(product_id, location_id, -quantity, lot_id=lot_id, package_id=package_id, owner_id=owner_id)
if available_qty < 0 and lot_id:
# see if we can compensate the negative quants with some untracked quants
untracked_qty = Quant._get_available_quantity(product_id, location_id, lot_id=False, package_id=package_id, owner_id=owner_id, strict=True)
if untracked_qty:
taken_from_untracked_qty = min(untracked_qty, abs(available_qty))
Quant._update_available_quantity(product_id, location_id, -taken_from_untracked_qty, lot_id=False, package_id=package_id, owner_id=owner_id)
Quant._update_available_quantity(product_id, location_id, taken_from_untracked_qty, lot_id=lot_id, package_id=package_id, owner_id=owner_id)
#.........这里部分代码省略.........
开发者ID:rmoorman,项目名称:odoo,代码行数:101,代码来源:stock_move_line.py
示例8: unlink
def unlink(self):
precision = self.env['decimal.precision'].precision_get('Product Unit of Measure')
for ml in self:
if ml.state in ('done', 'cancel'):
raise UserError(_('You can not delete pack operations of a done picking'))
# Unlinking a pack operation should unreserve.
if ml.location_id.should_impact_quants() and ml.product_id.type == 'product' and not float_is_zero(ml.product_qty, precision_digits=precision):
self.env['stock.quant']._decrease_reserved_quantity(ml.product_id, ml.location_id, ml.product_qty, lot_id=ml.lot_id,
package_id=ml.package_id, owner_id=ml.owner_id)
return super(StockMoveLine, self).unlink()
开发者ID:rossigee,项目名称:odoo,代码行数:10,代码来源:stock_move_line.py
示例9: _compute_timesheet_revenue
def _compute_timesheet_revenue(self):
for invoice in self:
for invoice_line in invoice.invoice_line_ids.filtered(lambda line: line.product_id.type == 'service').sorted(key=lambda inv_line: (inv_line.invoice_id, inv_line.id)):
uninvoiced_timesheet_lines = self.env['account.analytic.line'].sudo().search([
('so_line', 'in', invoice_line.sale_line_ids.ids),
('project_id', '!=', False),
('timesheet_invoice_id', '=', False),
('timesheet_invoice_type', 'in', ['billable_time', 'billable_fixed'])
])
# NOTE JEM : changing quantity (or unit price) of invoice line does not impact the revenue calculation. (FP specs)
if uninvoiced_timesheet_lines:
# delivered : update revenue with the prorata of number of hours on the timesheet line
if invoice_line.product_id.invoice_policy == 'delivery':
invoiced_price_per_hour = invoice_line.currency_id.round(invoice_line.price_subtotal / float(sum(uninvoiced_timesheet_lines.mapped('unit_amount'))))
# invoicing analytic lines of different currency
total_revenue_per_currency = dict.fromkeys(uninvoiced_timesheet_lines.mapped('currency_id').ids, 0.0)
for index, timesheet_line in enumerate(uninvoiced_timesheet_lines.sorted(key=lambda ts: (ts.date, ts.id))):
if index+1 != len(uninvoiced_timesheet_lines):
line_revenue = invoice_line.currency_id._convert(
invoiced_price_per_hour, timesheet_line.currency_id,
self.env.user.company_id, fields.Date.today()) * timesheet_line.unit_amount
total_revenue_per_currency[timesheet_line.currency_id.id] += line_revenue
else: # last line: add the difference to avoid rounding problem
total_revenue = sum([self.env['res.currency'].browse(currency_id)._convert(
amount, timesheet_line.currency_id,
self.env.user.company_id, fields.Date.today()
) for currency_id, amount in total_revenue_per_currency.items()])
line_revenue = invoice_line.currency_id._convert(
invoice_line.price_subtotal, timesheet_line.currency_id,
self.env.user.company_id, fields.Date.today()
) - total_revenue
timesheet_line.write({
'timesheet_invoice_id': invoice.id,
'timesheet_revenue': timesheet_line.currency_id.round(line_revenue),
})
# ordered : update revenue with the prorata of theorical revenue
elif invoice_line.product_id.invoice_policy == 'order':
zero_timesheet_revenue = uninvoiced_timesheet_lines.filtered(lambda line: line.timesheet_revenue == 0.0)
no_zero_timesheet_revenue = uninvoiced_timesheet_lines.filtered(lambda line: line.timesheet_revenue != 0.0)
# timesheet with zero theorical revenue keep the same revenue, but become invoiced (invoice_id set)
zero_timesheet_revenue.write({'timesheet_invoice_id': invoice.id})
# invoicing analytic lines of different currency
total_revenue_per_currency = dict.fromkeys(no_zero_timesheet_revenue.mapped('currency_id').ids, 0.0)
for index, timesheet_line in enumerate(no_zero_timesheet_revenue.sorted(key=lambda ts: (ts.date, ts.id))):
if index+1 != len(no_zero_timesheet_revenue):
price_subtotal_inv = invoice_line.currency_id._convert(
invoice_line.price_subtotal, timesheet_line.currency_id, self.env.user.company_id, fields.Date.today())
price_subtotal_sol = timesheet_line.so_line.currency_id._convert(
timesheet_line.so_line.price_subtotal, timesheet_line.currency_id, self.env.user.company_id, fields.Date.today())
if not float_is_zero(price_subtotal_sol, precision_rounding=timesheet_line.currency_id.rounding):
line_revenue = timesheet_line.timesheet_revenue * price_subtotal_inv / price_subtotal_sol
total_revenue_per_currency[timesheet_line.currency_id.id] += line_revenue
else:
line_revenue = timesheet_line.timesheet_revenue
total_revenue_per_currency[timesheet_line.currency_id.id] += line_revenue
else: # last line: add the difference to avoid rounding problem
last_price_subtotal_inv = invoice_line.currency_id._convert(
invoice_line.price_subtotal, timesheet_line.currency_id,
self.env.user.company_id, fields.Date.today())
total_revenue = sum([self.env['res.currency'].browse(currency_id)._convert(
amount, timesheet_line.currency_id,
self.env.user.company_id, fields.Date.today()
) for currency_id, amount in total_revenue_per_currency.items()])
line_revenue = last_price_subtotal_inv - total_revenue
timesheet_line.write({
'timesheet_invoice_id': invoice.id,
'timesheet_revenue': timesheet_line.currency_id.round(line_revenue),
})
开发者ID:Bubbles-IT,项目名称:odoo,代码行数:74,代码来源:account_invoice.py
示例10: _action_assign
def _action_assign(self):
""" Reserve stock moves by creating their stock move lines. A stock move is
considered reserved once the sum of `product_qty` for all its move lines is
equal to its `product_qty`. If it is less, the stock move is considered
partially available.
"""
assigned_moves = self.env['stock.move']
partially_available_moves = self.env['stock.move']
for move in self.filtered(lambda m: m.state in ['confirmed', 'waiting', 'partially_available']):
missing_reserved_uom_quantity = move.product_uom_qty - move.reserved_availability
missing_reserved_quantity = move.product_uom._compute_quantity(missing_reserved_uom_quantity, move.product_id.uom_id, rounding_method='HALF-UP')
if move.location_id.should_bypass_reservation()\
or move.product_id.type == 'consu':
# create the move line(s) but do not impact quants
if move.product_id.tracking == 'serial' and (move.picking_type_id.use_create_lots or move.picking_type_id.use_existing_lots):
for i in range(0, int(missing_reserved_quantity)):
self.env['stock.move.line'].create(move._prepare_move_line_vals(quantity=1))
else:
to_update = move.move_line_ids.filtered(lambda ml: ml.product_uom_id == move.product_uom and
ml.location_id == move.location_id and
ml.location_dest_id == move.location_dest_id and
ml.picking_id == move.picking_id and
not ml.lot_id and
not ml.package_id and
not ml.owner_id)
if to_update:
to_update[0].product_uom_qty += missing_reserved_uom_quantity
else:
# 'not' is removed at line 205 as 'not' is not working on odoo.sh so, for test purpose.
# if not move.picking_id.picking_type_id.show_reserved:
# self.env['stock.move.line'].create(move._prepare_move_line_vals(quantity=missing_reserved_quantity))
pass
assigned_moves |= move
else:
if not move.move_orig_ids:
if move.procure_method == 'make_to_order':
continue
# If we don't need any quantity, consider the move assigned.
need = missing_reserved_quantity
if float_is_zero(need, precision_rounding=move.product_id.uom_id.rounding):
assigned_moves |= move
continue
# Reserve new quants and create move lines accordingly.
forced_package_id = move.package_level_id.package_id or None
available_quantity = self.env['stock.quant']._get_available_quantity(move.product_id, move.location_id, package_id=forced_package_id)
if available_quantity <= 0:
continue
taken_quantity = move._update_reserved_quantity(need, available_quantity, move.location_id, package_id=forced_package_id, strict=False)
if float_is_zero(taken_quantity, precision_rounding=move.product_id.uom_id.rounding):
continue
if need == taken_quantity:
assigned_moves |= move
else:
partially_available_moves |= move
else:
# Check what our parents brought and what our siblings took in order to
# determine what we can distribute.
# `qty_done` is in `ml.product_uom_id` and, as we will later increase
# the reserved quantity on the quants, convert it here in
# `product_id.uom_id` (the UOM of the quants is the UOM of the product).
move_lines_in = move.move_orig_ids.filtered(lambda m: m.state == 'done').mapped('move_line_ids')
keys_in_groupby = ['location_dest_id', 'lot_id', 'result_package_id', 'owner_id']
def _keys_in_sorted(ml):
return (ml.location_dest_id.id, ml.lot_id.id, ml.result_package_id.id, ml.owner_id.id)
grouped_move_lines_in = {}
for k, g in groupby(sorted(move_lines_in, key=_keys_in_sorted), key=itemgetter(*keys_in_groupby)):
qty_done = 0
for ml in g:
qty_done += ml.product_uom_id._compute_quantity(ml.qty_done, ml.product_id.uom_id)
grouped_move_lines_in[k] = qty_done
move_lines_out_done = (move.move_orig_ids.mapped('move_dest_ids') - move)\
.filtered(lambda m: m.state in ['done'])\
.mapped('move_line_ids')
# As we defer the write on the stock.move's state at the end of the loop, there
# could be moves to consider in what our siblings already took.
moves_out_siblings = move.move_orig_ids.mapped('move_dest_ids') - move
moves_out_siblings_to_consider = moves_out_siblings & (assigned_moves + partially_available_moves)
reserved_moves_out_siblings = moves_out_siblings.filtered(lambda m: m.state in ['partially_available', 'assigned'])
move_lines_out_reserved = (reserved_moves_out_siblings | moves_out_siblings_to_consider).mapped('move_line_ids')
keys_out_groupby = ['location_id', 'lot_id', 'package_id', 'owner_id']
def _keys_out_sorted(ml):
return (ml.location_id.id, ml.lot_id.id, ml.package_id.id, ml.owner_id.id)
grouped_move_lines_out = {}
for k, g in groupby(sorted(move_lines_out_done, key=_keys_out_sorted), key=itemgetter(*keys_out_groupby)):
qty_done = 0
for ml in g:
qty_done += ml.product_uom_id._compute_quantity(ml.qty_done, ml.product_id.uom_id)
grouped_move_lines_out[k] = qty_done
for k, g in groupby(sorted(move_lines_out_reserved, key=_keys_out_sorted), key=itemgetter(*keys_out_groupby)):
grouped_move_lines_out[k] = sum(self.env['stock.move.line'].concat(*list(g)).mapped('product_qty'))
available_move_lines = {key: grouped_move_lines_in[key] - grouped_move_lines_out.get(key, 0) for key in grouped_move_lines_in.keys()}
# pop key if the quantity available amount to 0
available_move_lines = dict((k, v) for k, v in available_move_lines.items() if v)
if not available_move_lines:
continue
#.........这里部分代码省略.........
开发者ID:VisionSolutions,项目名称:flinders2,代码行数:101,代码来源:stock_picking.py
注:本文中的odoo.tools.float_utils.float_is_zero函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论