本文整理汇总了Python中trytond.pool.Pool.compute_qty方法的典型用法代码示例。如果您正苦于以下问题:Python Pool.compute_qty方法的具体用法?Python Pool.compute_qty怎么用?Python Pool.compute_qty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trytond.pool.Pool
的用法示例。
在下文中一共展示了Pool.compute_qty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_carrier_context
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute_qty [as 别名]
def _get_carrier_context(self):
Uom = Pool().get('product.uom')
context = super(ShipmentOut, self)._get_carrier_context()
if not self.carrier:
return context
if self.carrier.carrier_cost_method != 'weight':
return context
context = context.copy()
weights = []
context['weights'] = weights
lines = self.inventory_moves or []
keyfunc = partial(self._group_parcel_key, lines)
lines = sorted(lines, key=keyfunc)
for key, parcel in groupby(lines, key=keyfunc):
weight = 0
for line in parcel:
if (line.product
and line.quantity
and line.uom
and line.product.weight):
quantity = Uom.compute_qty(line.uom, line.quantity,
line.product.default_uom, round=False)
weight += Uom.compute_qty(line.product.weight_uom,
line.product.weight * quantity,
self.carrier.weight_uom, round=False)
weights.append(weight)
return context
示例2: _get_carrier_context
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute_qty [as 别名]
def _get_carrier_context(self):
Uom = Pool().get('product.uom')
context = super(Sale, self)._get_carrier_context()
if self.carrier.carrier_cost_method != 'weight':
return context
context = context.copy()
weights = []
context['weights'] = weights
lines = self.lines or []
keyfunc = partial(self._group_parcel_key, lines)
lines = sorted(lines, key=keyfunc)
for key, parcel in groupby(lines, key=keyfunc):
weight = 0
for line in parcel:
if (getattr(line, 'product', None)
and getattr(line, 'quantity', None)
and getattr(line, 'unit', None)):
quantity = Uom.compute_qty(line.unit, line.quantity,
line.product.default_uom, round=False)
if line.product.weight:
weight += Uom.compute_qty(line.product.weight_uom,
line.product.weight * quantity,
self.carrier.weight_uom, round=False)
weights.append(weight)
return context
示例3: compute
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute_qty [as 别名]
def compute(self, party, product, unit_price, quantity, uom,
pattern=None):
'''
Compute price based on price list of party
:param unit_price: a Decimal for the default unit price in the
company's currency and default uom of the product
:param quantity: the quantity of product
:param uom: a instance of the product.uom
:param pattern: a dictionary with price list field as key
and match value as value
:return: the computed unit price
'''
Uom = Pool().get('product.uom')
if pattern is None:
pattern = {}
pattern = pattern.copy()
pattern['product'] = product and product.id or None
pattern['quantity'] = Uom.compute_qty(uom, quantity,
product.default_uom, round=False)
for line in self.lines:
if line.match(pattern):
with Transaction().set_context(
self._get_context_price_list_line(party, product,
unit_price, quantity, uom)):
return line.get_unit_price()
return unit_price
示例4: on_change_supplier_invoice_line
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute_qty [as 别名]
def on_change_supplier_invoice_line(self):
pool = Pool()
Currency = pool.get('currency.currency')
Unit = Pool().get('product.uom')
if not self.supplier_invoice_line:
self.quantity = None
self.value = None
self.start_date = self.default_start_date()
return
invoice_line = self.supplier_invoice_line
invoice = invoice_line.invoice
if invoice.company.currency != invoice.currency:
with Transaction().set_context(date=invoice.currency_date):
self.value = Currency.compute(
invoice.currency, invoice_line.amount,
invoice.company.currency)
else:
self.value = invoice_line.amount
if invoice.invoice_date:
self.purchase_date = invoice.invoice_date
self.start_date = invoice.invoice_date
if invoice_line.product.depreciation_duration:
duration = relativedelta.relativedelta(
months=int(invoice_line.product.depreciation_duration),
days=-1)
self.end_date = self.start_date + duration
if not self.unit:
self.quantity = invoice_line.quantity
else:
self.quantity = Unit.compute_qty(invoice_line.unit,
invoice_line.quantity, self.unit)
示例5: get_shipping_rate
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute_qty [as 别名]
def get_shipping_rate(self, carrier, carrier_service=None, silent=False):
"""
Call the rates service and get possible quotes for shipment for eligible
mail classes
"""
Currency = Pool().get('currency.currency')
UOM = Pool().get('product.uom')
ModelData = Pool().get('ir.model.data')
if carrier.carrier_cost_method != "endicia":
return super(Sale, self).get_shipping_rate(
carrier, carrier_service, silent
)
from_address = self._get_ship_from_address()
if self.shipment_address.country.code == "US":
mailclass_type = "Domestic"
else:
mailclass_type = "International"
uom_oz = UOM.search([('symbol', '=', 'oz')])[0]
# Endicia only support 1 decimal place in weight
weight_oz = "%.1f" % UOM.compute_qty(
self.weight_uom, self.weight, uom_oz
)
to_zip = self.shipment_address.zip
if mailclass_type == 'Domestic':
to_zip = to_zip and to_zip[:5]
else:
# International
to_zip = to_zip and to_zip[:15]
postage_rates_request = PostageRatesAPI(
mailclass=mailclass_type,
weightoz=weight_oz,
from_postal_code=from_address.zip[:5],
to_postal_code=to_zip,
to_country_code=self.shipment_address.country.code,
accountid=carrier.endicia_account_id,
requesterid=carrier.endicia_requester_id,
passphrase=carrier.endicia_passphrase,
test=carrier.endicia_is_test,
)
# Logging.
logger.debug(
'Making Postage Rates Request for shipping rates of'
'Sale ID: {0} and Carrier ID: {1}'
.format(self.id, carrier.id)
)
logger.debug('--------POSTAGE RATES REQUEST--------')
logger.debug(str(postage_rates_request.to_xml()))
logger.debug('--------END REQUEST--------')
try:
response_xml = postage_rates_request.send_request()
response = objectify_response(response_xml)
except RequestError, e:
self.raise_user_error(unicode(e))
示例6: get_weight
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute_qty [as 别名]
def get_weight(self, weight_uom, silent=False):
"""
Returns weight as required for carriers
:param weight_uom: Weight uom used by carriers
:param silent: Raise error if not silent
"""
ProductUom = Pool().get('product.uom')
if not self.product or self.quantity <= 0 or \
self.product.type == 'service':
return 0
if not self.product.weight:
if silent:
return 0
self.raise_user_error(
'weight_required',
error_args=(self.product.name,)
)
# Find the quantity in the default uom of the product as the weight
# is for per unit in that uom
if self.unit != self.product.default_uom:
quantity = ProductUom.compute_qty(
self.unit,
self.quantity,
self.product.default_uom
)
else:
quantity = self.quantity
weight = self.product.weight * quantity
# Compare product weight uom with the weight uom used by carrier
# and calculate weight if botth are not same
if self.product.weight_uom.symbol != weight_uom.symbol:
weight = ProductUom.compute_qty(
self.product.weight_uom,
weight,
weight_uom,
)
return weight
示例7: _get_rate_request_xml
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute_qty [as 别名]
def _get_rate_request_xml(self, carrier, carrier_service):
SaleConfiguration = Pool().get("sale.configuration")
Uom = Pool().get("product.uom")
config = SaleConfiguration(1)
code = length = width = height = dimensions_symbol = None
box_type = config.ups_box_type
if box_type:
code = box_type.code
length = box_type.length
height = box_type.height
width = box_type.width
dimensions_symbol = box_type.distance_unit and box_type.distance_unit.symbol.upper()
package_type = RatingService.packaging_type(Code=code)
package_weight = RatingService.package_weight_type(
Weight="%.2f" % Uom.compute_qty(self.weight_uom, self.weight, carrier.ups_weight_uom),
Code=carrier.ups_weight_uom_code,
)
package_service_options = RatingService.package_service_options_type(
RatingService.insured_value_type(MonetaryValue="0")
)
args = [package_type, package_weight, package_service_options]
# Only send dimensions if box type has all information
if length and width and height and dimensions_symbol:
package_dimensions = RatingService.dimensions_type(
Code=dimensions_symbol, Length=str(length), Width=str(width), Height=str(height)
)
args.append(package_dimensions)
shipment_args = [RatingService.package_type(*args)]
from_address = self._get_ship_from_address()
shipment_args.extend(
[
from_address.to_ups_shipper(carrier=carrier), # Shipper
self.shipment_address.to_ups_to_address(), # Ship to
from_address.to_ups_from_address(), # Ship from
]
)
if carrier.ups_negotiated_rates:
shipment_args.append(RatingService.rate_information_type(negotiated=True))
if carrier_service:
# TODO: handle ups_saturday_delivery
shipment_args.append(RatingService.service_type(Code=carrier_service.code))
request_option = E.RequestOption("Rate")
else:
request_option = E.RequestOption("Shop")
return RatingService.rating_request_type(E.Shipment(*shipment_args), RequestOption=request_option)
示例8: compute_factor
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute_qty [as 别名]
def compute_factor(self, product, quantity, uom):
"""
Compute factor for an output product
"""
Uom = Pool().get("product.uom")
for output in self.outputs:
if output.product == product:
if not output.quantity:
return 0.0
quantity = Uom.compute_qty(uom, quantity, output.uom, round=False)
return quantity / output.quantity
示例9: on_change_asset
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute_qty [as 别名]
def on_change_asset(self):
Uom = Pool().get('product.uom')
if self.asset:
quantity = self.asset.quantity
if self.unit:
quantity = Uom.compute_qty(self.asset.unit, quantity,
self.unit)
self.quantity = quantity
else:
self.quantity = quantity
self.unit = self.unit
示例10: get_weight_for_endicia
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute_qty [as 别名]
def get_weight_for_endicia(self):
"""
Returns weight as required for endicia.
Upward rounded integral values in Oz
"""
ProductUom = Pool().get('product.uom')
if self.product.type == 'service':
return 0
if not self.product.weight:
self.raise_user_error(
'weight_required',
error_args=(self.product.name,)
)
# Find the quantity in the default uom of the product as the weight
# is for per unit in that uom
if self.uom != self.product.default_uom:
quantity = ProductUom.compute_qty(
self.uom,
self.quantity,
self.product.default_uom
)
else:
quantity = self.quantity
weight = float(self.product.weight) * quantity
# Endicia by default uses oz for weight purposes
if self.product.weight_uom.symbol != 'oz':
ounce, = ProductUom.search([('symbol', '=', 'oz')])
weight = ProductUom.compute_qty(
self.product.weight_uom,
weight,
ounce
)
return math.ceil(weight)
示例11: get_total_volume
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute_qty [as 别名]
def get_total_volume(self, _ids):
"""Compute the total volume sum"""
if self.total_volume_uom is None:
return 0.0
total = 0.0
for trunks in self.trunks:
if trunks is None or trunks.total_cubing is None:
continue
total += trunks.get_total_cubing(None)
Uom = Pool().get('product.uom')
m3_id = Id('product', 'uom_cubic_meter').pyson()
m3 = Uom(m3_id)
return Uom.compute_qty(m3, total, self.total_volume_uom)
示例12: get_mean_volume
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute_qty [as 别名]
def get_mean_volume(self, ids):
"""Return the mean volume in the selected unit"""
if self.total_trunks_count == 0 or self.mean_volume_uom is None:
return 0.0
total = 0.0
for trunks in self.trunks:
if trunks is None or trunks.total_cubing is None:
continue
total += trunks.get_total_cubing(None)
Uom = Pool().get('product.uom')
m3_id = Id('product', 'uom_cubic_meter').pyson()
m3 = Uom(m3_id)
return Uom.compute_qty(m3, total / float(self.total_trunks_count), self.mean_volume_uom)
示例13: get_monetary_value_for_ups
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute_qty [as 别名]
def get_monetary_value_for_ups(self):
"""
Returns monetary_value as required for ups
"""
ProductUom = Pool().get("product.uom")
# Find the quantity in the default uom of the product as the weight
# is for per unit in that uom
if self.uom != self.product.default_uom:
quantity = ProductUom.compute_qty(self.uom, self.quantity, self.product.default_uom)
else:
quantity = self.quantity
return Decimal(self.product.list_price) * Decimal(quantity)
示例14: _update_fifo_out_product_cost_price
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute_qty [as 别名]
def _update_fifo_out_product_cost_price(self):
"""
Update the product cost price of the given product on the move. Update
fifo_quantity on the concerned incomming moves. Return the
cost price for outputing the given product and quantity.
"""
Uom = Pool().get("product.uom")
total_qty = Uom.compute_qty(self.uom, self.quantity, self.product.default_uom, round=False)
fifo_moves = self.product.template.get_fifo_move(total_qty)
cost_price = Decimal("0.0")
consumed_qty = 0.0
for move, move_qty in fifo_moves:
consumed_qty += move_qty
move_unit_price = Uom.compute_price(move.uom, move.unit_price, move.product.default_uom)
cost_price += move_unit_price * Decimal(str(move_qty))
move.quantity = move_qty
move._update_product_cost_price("out")
move_qty = Uom.compute_qty(self.product.default_uom, move_qty, move.uom, round=False)
# Use write as move instance quantity was modified to call
# _update_product_cost_price
self.write([self.__class__(move.id)], {"fifo_quantity": (move.fifo_quantity or 0.0) + move_qty})
if Decimal(str(consumed_qty)) != Decimal("0"):
cost_price = cost_price / Decimal(str(consumed_qty))
if cost_price != Decimal("0"):
digits = self.__class__.cost_price.digits
return cost_price.quantize(Decimal(str(10.0 ** -digits[1])))
else:
return self.product.cost_price
示例15: get_ups_package_container_rate
# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import compute_qty [as 别名]
def get_ups_package_container_rate(self):
"""
Return UPS package container for a single package
"""
Uom = Pool().get('product.uom')
shipment = self.shipment
carrier = shipment.carrier
if self.box_type:
code = self.box_type.code
length = self.box_type.length
height = self.box_type.height
width = self.box_type.width
dimensions_symbol = self.box_type.distance_unit and \
self.box_type.distance_unit.symbol.upper()
else:
code = '02'
length = self.length
height = self.height
width = self.width
dimensions_symbol = self.distance_unit and \
self.distance_unit.symbol.upper()
package_type = RatingService.packaging_type(Code=code)
package_weight = RatingService.package_weight_type(
Weight="%.2f" % Uom.compute_qty(
self.weight_uom, self.weight, carrier.ups_weight_uom
),
Code=carrier.ups_weight_uom_code,
)
package_service_options = RatingService.package_service_options_type(
RatingService.insured_value_type(MonetaryValue='0')
)
args = [package_type, package_weight, package_service_options]
# Only send dimensions if the box type is 'Customer Supplied Package'
if code == '02' and length and width and height and dimensions_symbol:
package_dimensions = RatingService.dimensions_type(
Code=dimensions_symbol,
Length=str(length),
Width=str(width),
Height=str(height)
)
args.append(package_dimensions)
package_container = RatingService.package_type(*args)
return package_container