def get_design_sale_line(self, sale, quote_line): ''' Return sale line for opportunity line ''' SaleLine = Pool().get('sale.line') Uom = Pool().get('product.uom') sale_line = SaleLine( type='line', product=quote_line.design.product, sale=sale, description=None, ) sale_line.on_change_product() sale_line.unit = quote_line.design.sale_uom quantity = Uom.compute_qty(quote_line.design.quotation_uom, quote_line.quantity, sale_line.unit, round=True) sale_line.quantity = quantity unit_price = quote_line.manual_list_price or quote_line.unit_price unit_price = Uom.compute_price(sale_line.product.default_uom, unit_price, sale_line.unit) sale_line.unit_price = round(unit_price, price_digits[1]) return sale_line
def get_cost(self, name=None): Uom = Pool().get('product.uom') if not self.product or not self.unit: return Decimal('0.0') cost = Uom.compute_price( self.product.default_uom, self.product.cost_price, self.unit) return cost
def get_price_uom(products, name): Uom = Pool().get('product.uom') res = {} field = name[:-4] if Transaction().context.get('uom'): to_uom = Uom(Transaction().context['uom']) for product in products: res[product.id] = Uom.compute_price( product.default_uom, getattr(product, field), to_uom) else: for product in products: res[product.id] = getattr(product, field) return res
def get_price_uom(self, ids, name): product_uom_obj = Pool().get('product.uom') res = {} field = name[:-4] if Transaction().context.get('uom'): to_uom = product_uom_obj.browse( Transaction().context['uom']) for product in self.browse(ids): res[product.id] = product_uom_obj.compute_price( product.default_uom, product[field], to_uom) else: for product in self.browse(ids): res[product.id] = product[field] return res
def get_price_uom(products, name): Uom = Pool().get('product.uom') res = {} field = name[:-4] if Transaction().context.get('uom'): to_uom = Uom(Transaction().context['uom']) else: to_uom = None for product in products: price = getattr(product, field) if to_uom and product.default_uom.category == to_uom.category: res[product.id] = Uom.compute_price(product.default_uom, price, to_uom) else: res[product.id] = price return res
def get_price_uom(products, name): Uom = Pool().get('product.uom') res = {} field = name[:-4] if Transaction().context.get('uom'): to_uom = Uom(Transaction().context['uom']) else: to_uom = None for product in products: price = getattr(product, field) if to_uom and product.default_uom.category == to_uom.category: res[product.id] = Uom.compute_price( product.default_uom, price, to_uom) else: res[product.id] = price return res
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
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