Exemple #1
0
 def onchange_qty(self, context):
     data = context["data"]
     path = context["path"]
     line = get_data_path(data, path, parent=True)
     prod_id = line.get("product_id")
     if not prod_id:
         return {}
     prod = get_model("product").browse(prod_id)
     pricelist_id = data["price_list_id"]
     qty = line["qty"]
     if line.get("unit_price") is None:
         price = None
         if pricelist_id:
             price = get_model("price.list").get_price(pricelist_id, prod.id, qty)
             price_list = get_model("price.list").browse(pricelist_id)
             price_currency_id = price_list.currency_id.id
         if price is None:
             price = prod.sale_price
             settings = get_model("settings").browse(1)
             price_currency_id = settings.currency_id.id
         if price is not None:
             currency_id = data["currency_id"]
             price_cur = get_model("currency").convert(price, price_currency_id, currency_id)
             line["unit_price"] = price_cur
     data = self.update_amounts(context)
     return data
 def update_cost_price(self, context):
     data = context["data"]
     path = context["path"]
     line = get_data_path(data, path, parent=True)
     cost_price_cur=line["cost_price_cur"] or 0
     qty=line["qty"] or 0
     currency_id=data["currency_id"]
     if not currency_id:
         raise Exception("Missing currency")
     currency=get_model("currency").browse(currency_id)
     currency_rate=data["currency_rate"]
     date=data["date"]
     settings=get_model("settings").browse(1)
     if not currency_rate:
         if currency_id == settings.currency_id.id:
             currency_rate = 1
         else:
             rate_from = currency.get_rate(date=date)
             if not rate_from:
                 raise Exception("Missing currency rate for %s" % currency.code)
             rate_to = settings.currency_id.get_rate(date=date)
             if not rate_to:
                 raise Exception("Missing currency rate for %s" % settings.currency_id.code)
             currency_rate = rate_from / rate_to
     cost_price=get_model("currency").convert(cost_price_cur,currency_id,settings.currency_id.id,rate=currency_rate)
     cost_amount=cost_price*qty
     line["cost_price"]=cost_price
     line["cost_amount"]=cost_amount
     return data
 def onchange_product(self, context):
     data = context["data"]
     type = data["type"]
     path = context["path"]
     contact_id = data["contact_id"]
     contact = get_model("contact").browse(contact_id)
     line = get_data_path(data, path, parent=True)
     prod_id = line.get("product_id")
     if not prod_id:
         return {}
     prod = get_model("product").browse(prod_id)
     line["description"] = prod.description
     line["qty"] = 1
     if prod.uom_id is not None:
         line["uom_id"] = prod.uom_id.id
     if type == "out":
         if prod.sale_price is not None:
             line["unit_price"] = prod.sale_price
         if prod.sale_account_id is not None:
             line["account_id"] = prod.sale_account_id.id
         if prod.sale_tax_id is not None:
             line["tax_id"] = contact.tax_receivable_id.id or prod.sale_tax_id.id
     elif type == "in":
         if prod.purchase_price is not None:
             line["unit_price"] = prod.purchase_price
         if prod.purchase_account_id is not None:
             line["account_id"] = prod.purchase_account_id.id
         if prod.purchase_tax_id is not None:
             line["tax_id"] = contact.tax_payable_id.id or prod.purchase_tax_id.id
     data = self.update_amounts(context)
     return data
Exemple #4
0
 def onchange_product(self, context):
     data = context["data"]
     path = context["path"]
     line = get_data_path(data, path, parent=True)
     prod_id = line.get("product_id")
     if not prod_id:
         return {}
     prod = get_model("product").browse(prod_id)
     line["description"] = prod.description
     line["qty"] = 1
     if prod.uom_id is not None:
         line["uom_id"] = prod.uom_id.id
     pricelist_id = data["price_list_id"]
     price = None
     if pricelist_id:
         price = get_model("price.list").get_price(pricelist_id, prod.id, 1)
         price_list = get_model("price.list").browse(pricelist_id)
         price_currency_id = price_list.currency_id.id
     if price is None:
         price = prod.purchase_price
         settings = get_model("settings").browse(1)
         price_currency_id = settings.currency_id.id
     if price is not None:
         currency_id = data["currency_id"]
         price_cur = get_model("currency").convert(price, price_currency_id, currency_id)
         line["unit_price"] = price_cur
     if prod.purchase_tax_id is not None:
         line["tax_id"] = prod.purchase_tax_id.id
     if prod.location_id:
         line["location_id"] = prod.location_id.id
     data = self.update_amounts(context)
     return data
 def onchange_book(self, context={}):
     data = context["data"]
     path = context["path"]
     line = get_data_path(data,path,parent=True)
     book_id = line["book_id"]
     book = get_model("bookstore.book").browse(book_id)
     line["unit_price"]=book.cost
     return data
Exemple #6
0
 def get_line_desc(self, context):
     data = context["data"]
     path = context["path"]
     if not data.get("default_line_desc"):
         return
     if not get_data_path(data, path):
         set_data_path(data, path, data.get("narration"))
     return data
 def onchange_product(self, context={}):
     data = context.get('data')
     path = context.get('path')
     line = get_data_path(data, path, parent=True)
     product = get_model('product').browse(line['product_id'])
     line['description'] = product.description if product.description else "-"
     line['uom_id'] = product.uom_id.id
     return data
 def onchange_to_product(self, context={}):
     data = context["data"]
     path = context["path"]
     line = get_data_path(data, path, parent=True)
     prod_id = line.get("product_id")
     prod = get_model("product").browse(prod_id)
     line["uom_id"] = prod.uom_id.id
     line["qty"] = 1
     return data
Exemple #9
0
 def onchange_product(self,context={}):
     data=context['data']
     path=context['path']
     line=get_data_path(data,path,parent=True)
     product_id=line['product_id']
     if product_id:
         product=get_model('product').browse(product_id)
         line['uom_id']=product.uom_id.id
     return data
Exemple #10
0
 def onchange_product(self, context):
     data = context["data"]
     path = context["path"]
     line = get_data_path(data, path, parent=True)
     product_id = line["product_id"]
     prod = get_model("product").browse(product_id)
     line["description"] = prod.description
     line["unit_price"] = prod.cost_price
     return data
 def onchange_product(self, context):
     data = context["data"]
     path = context["path"]
     line = get_data_path(data, path, parent=True)
     prod_id = line.get("product_id")
     if not prod_id:
         return {}
     prod = get_model("product").browse(prod_id)
     line["uom_id"] = prod.uom_id.id
     return data
Exemple #12
0
 def onchange_est_margin(self,context={}):
     data=context["data"]
     path=context["path"]
     line=get_data_path(data,path,parent=True)
     margin=line["est_margin_percent_input"]
     amt=line["est_cost_amount"]/(1-margin/Decimal(100))
     price=round(amt/line["qty"])
     line["unit_price"]=price
     self.update_amounts(context)
     return data
 def onchange_lot(self, context):
     data = context["data"]
     loc_id = data["location_from_id"]
     path = context["path"]
     line = get_data_path(data, path, parent=True)
     prod_id = line["product_id"]
     lot_id = line["lot_id"]
     res = get_model("stock.location").compute_balance([loc_id], prod_id, lot_id=lot_id)
     line["qty"] = res["bal_qty"]
     return data
 def onchange_qc_test(self, context):
     data = context["data"]
     path = context["path"]
     line = get_data_path(data, path, parent=True)
     test_id = line.get("test_id")
     if not test_id:
         return
     test = get_model("qc.test").browse(test_id)
     line["min_value"] = test.min_value
     line["max_value"] = test.max_value
     return data
 def onchange_account(self, context):
     data = context["data"]
     path = context["path"]
     line = get_data_path(data, path, parent=True)
     acc_id = line.get("account_id")
     if not acc_id:
         return {}
     acc = get_model("account.account").browse(acc_id)
     line["tax_id"] = acc.tax_id.id
     data = self.update_amounts(context)
     return data
Exemple #16
0
 def onchange_product(self, context):
     data = context["data"]
     path = context["path"]
     line = get_data_path(data, path, parent=True)
     prod_id = line.get("product_id")
     if not prod_id:
         return {}
     prod = get_model("product").browse(prod_id)
     line["qty"] = 1
     if prod.uom_id is not None:
         line["uom_id"] = prod.uom_id.id
     if data["type"] == "in":
         if prod.purchase_price is not None:
             line["cost_price_cur"] = prod.purchase_price
     return data
Exemple #17
0
 def onchange_uom(self, context):
     data = context["data"]
     path = context["path"]
     line = get_data_path(data, path, parent=True)
     prod_id = line.get("product_id")
     if not prod_id:
         return {}
     prod = get_model("product").browse(prod_id)
     uom_id = line.get("uom_id")
     if not uom_id:
         return {}
     uom = get_model("uom").browse(uom_id)
     if prod.sale_price is not None:
         line["unit_price"] = prod.sale_price * uom.ratio / prod.uom_id.ratio
     data = self.update_amounts(context)
     return data
 def onchange_qc_value(self, context):
     data = context["data"]
     path = context["path"]
     line = get_data_path(data, path, parent=True)
     try:
         value = float(line.get("value"))
     except:
         return
     min_value = line.get("min_value")
     max_value = line.get("max_value")
     if min_value and value < min_value:
         line["result"] = "no"
     elif max_value and value > max_value:
         line["result"] = "no"
     else:
         line["result"] = "yes"
     return data
Exemple #19
0
 def onchange_product(self, context):
     data = context["data"]
     loc_id = data["location_id"]
     path = context["path"]
     line = get_data_path(data, path, parent=True)
     prod_id = line.get("product_id")
     if not prod_id:
         return {}
     prod = get_model("product").browse(prod_id)
     lot_id = line.get("lot_id")
     qty = get_model("stock.balance").get_qty_phys(loc_id, prod_id, lot_id)
     unit_price = get_model("stock.balance").get_unit_price(loc_id, prod_id)
     line["bin_location"] = prod.bin_location
     line["prev_qty"] = qty
     line["prev_cost_price"] = unit_price
     line["new_qty"] = qty
     line["unit_price"] = unit_price
     line["uom_id"] = prod.uom_id.id
     return data
Exemple #20
0
 def onchange_item(self, context={}):
     data = context["data"]
     emp_id = data.get("employee_id")
     if not emp_id:
         return
     date = data.get("date")
     emp = get_model("hr.employee").browse(emp_id)
     path = context["path"]
     line = get_data_path(data, path, parent=True)
     item_id = line["payitem_id"]
     if not item_id:
         return
     item = get_model("hr.payitem").browse(item_id)
     qty, rate = item.compute(context={"employee_id": emp_id, "date": date})
     line["qty"] = qty
     line["rate"] = rate
     line["amount"] = qty * rate
     self.update_amounts(context=context)
     return data
Exemple #21
0
    def onchange_cost_product(self,context):
        data=context["data"]
        path=context["path"]
        line=get_data_path(data,path,parent=True)
        prod_id=line.get("product_id")
        if prod_id:
            prod=get_model("product").browse(prod_id)
            line["description"]=prod.name
            line["list_price"]=prod.purchase_price
            line["purchase_price"]=prod.purchase_price
            line["landed_cost"]=prod.landed_cost
            line["qty"]=1
            line["uom_id"]=prod.uom_id.id
            line["currency_id"]=prod.purchase_currency_id.id
            line["purchase_duty_percent"]=prod.purchase_duty_percent
            line["purchase_ship_percent"]=prod.purchase_ship_percent
            line["landed_cost"]=prod.landed_cost
            line["purcase_price"]=prod.purchase_price

            if prod.suppliers:
                line["supplier_id"]=prod.suppliers[0].supplier_id.id
        return data
 def onchange_uom(self, context):
     data = context["data"]
     path = context["path"]
     line = get_data_path(data, path, parent=True)
     prod_id = line.get("product_id")
     uom_id = line.get("uom_id")
     pricelist_id = data["price_list_id"]
     price=None
     if not prod_id:return data
     prod = get_model("product").browse(prod_id)
     if not uom_id: return data
     uom = get_model("uom").browse(uom_id)
     if pricelist_id:
         price = get_model("price.list").get_price(pricelist_id, prod.id, 1)
     if price is None:
         price = prod.purchase_price
     if price is not None:
         if prod.purchase_currency_id and prod.purchase_currency_id.id != data['currency_id']:
             price=get_model("currency").convert(price, prod.purchase_currency_id.id, data['currency_id'])
     line["unit_price"] = price * uom.ratio / prod.uom_id.ratio
     if prod.purchase_uom_id:
         line["unit_price"] = price * uom.ratio / prod.purchase_uom_id.ratio or 1
     data = self.update_amounts(context)
     return data
Exemple #23
0
 def onchange_product(self, context):
     data = context["data"]
     contact_id = data.get("contact_id")
     if contact_id:
         contact = get_model("contact").browse(contact_id)
     else:
         contact = None
     path = context["path"]
     line = get_data_path(data, path, parent=True)
     prod_id = line.get("product_id")
     if not prod_id:
         return {}
     prod = get_model("product").browse(prod_id)
     line["description"] = prod.description or "/"
     line["qty"] = 1
     line["uom_id"] = prod.sale_uom_id.id or prod.uom_id.id
     pricelist_id = data["price_list_id"]
     price = None
     if pricelist_id:
         price = get_model("price.list").get_price(pricelist_id, prod.id, 1)
         price_list = get_model("price.list").browse(pricelist_id)
         price_currency_id = price_list.currency_id.id
     if price is None:
         price = prod.sale_price
         settings = get_model("settings").browse(1)
         price_currency_id = settings.currency_id.id
     if price is not None:
         currency_id = data["currency_id"]
         price_cur = get_model("currency").convert(price, price_currency_id, currency_id)
         line["unit_price"] = price_cur
     if prod.sale_tax_id is not None:
         line["tax_id"] = prod.sale_tax_id.id
     if prod.location_id:
         line["location_id"] = prod.location_id.id
     data = self.update_amounts(context)
     return data
    def onchange_product(self, context={}):
        data = context['data']
        path = context['path']
        line = get_data_path(data, path, parent=True)
        product_model = get_model("product").browse(line.get("product_id"))
        line["description"] = product_model.description
        if product_model.get("purchase_account_id"):
            line["account_id"] = product_model.purchase_account_id.id
        else:
            line[
                "account_id"] = product_model.categ_id.purchase_account_id.id if product_model.categ_id.purchase_account_id else None

        if product_model.purchase_tax_id is not None and product_model.purchase_tax_id.id:
            line["tax_id"] = product_model.purchase_tax_id.id
        else:
            if product_model.categ_id.purchase_tax_id is not None and product_model.categ_id.purchase_tax_id.id:
                line["tax_id"] = product_model.categ_id.purchase_tax_id.id
            else:
                line["tax_id"] = None
        if line['tax_id']:
            line['tax_type'] = "tax_ex"
        else:
            line['tax_type'] = None
        if data.get("fund_id"):
            fund_id = get_model("petty.cash.fund").browse(
                int(data.get("fund_id")))
            if fund_id:
                data[
                    "number_receive"] = fund_id.number_receive.id if fund_id.number_receive else None
                data["amount_bal"] = fund_id.acc_bal
                if data.get("type") == "out":
                    line[
                        'track_id'] = fund_id.track_id.id if fund_id.track_id else None
                    line[
                        'track2_id'] = fund_id.track2_id.id if fund_id.track2_id else None
        return data
 def update_cost(self,context={}):
     data =context["data"]
     path = context["path"]
     line = get_data_path(data,path,parent=True)
     line["total_cost"] = line['qty']*line['unit_price']
Exemple #26
0
    def update_cost_amount(self, context={}):
        settings = get_model('settings').browse(1)
        data = context['data']
        path = context['path']
        line = get_data_path(data, path, parent=True)

        pur_price = round(Decimal(line['purchase_price'] or 0), 2)
        purchase_ship_percent = round(
            Decimal(line['purchase_ship_percent'] or 0), 2)
        purchase_duty_percent = round(
            Decimal(line['purchase_duty_percent'] or 0), 2)
        qty = round(Decimal(line['qty'] or 0), 2)
        amount = Decimal(0)

        landed_cost = round(
            pur_price + (pur_price * (purchase_ship_percent / 100)) +
            (pur_price * (purchase_duty_percent / 100)), 2)
        amount = round((qty) * (landed_cost), 2)

        line['landed_cost'] = landed_cost
        prod = get_model('product').browse(line.get('product_id'))
        if prod.purchase_currency_id:
            if prod.purchase_currency_id.id == settings.currency_id.id:
                if data["currency_id"] == settings.currency_id.id:
                    line['amount'] = amount
                    line['amount_conv'] = amount
                else:
                    cost_conv = get_model("currency").convert(
                        amount,
                        settings.currency_id.id,
                        data['currency_id'],
                        date=data['date'])
                    line['amount'] = amount
                    line['amount_conv'] = cost_conv
            else:
                cost = get_model("currency").convert(
                    amount,
                    prod.purchase_currency_id.id,
                    settings.currency_id.id,
                    date=data['date'])
                cost_conv = get_model("currency").convert(
                    cost,
                    settings.currency_id.id,
                    data['currency_id'],
                    date=data['date'])
                line['amount'] = cost
                line['amount_conv'] = cost_conv
        else:
            if data["currency_id"] != settings.currency_id.id:
                cost = get_model("currency").convert(amount,
                                                     data['currency_id'],
                                                     settings.currency_id.id,
                                                     date=data['date'])
                cost_conv = get_model("currency").convert(
                    cost,
                    settings.currency_id.id,
                    data['currency_id'],
                    date=data['date'])
                line['amount'] = cost
                line['amount_conv'] = cost_conv
            else:
                line['amount'] = amount
                line['amount_conv'] = amount
        return data
    def onchange_product(self, context):
        data = context["data"]
        path = context["path"]
        settings=get_model("settings").browse(1)
        line = get_data_path(data, path, parent=True)
        prod_id = line.get("product_id")
        if not prod_id:
            return {}
        prod_cur_id = None
        prod = get_model("product").browse(prod_id)
        line["description"] = prod.description
        line["qty"] = prod.purchase_min_qty or 1
        line["uom_id"] = prod.purchase_uom_id.id or prod.uom_id.id
        pricelist_id = data["price_list_id"]
        price = 0
        if pricelist_id:
            price = get_model("price.list").get_price(pricelist_id, prod.id, 1) or 0
            prod_cur_id = get_model("price.list").browse(pricelist_id).currency_id.id or None
        if not price or price == 0:
            price = prod.purchase_price or 0
            if not prod_cur_id:
                prod_cur_id = prod.purchase_currency_id.id or None
        currency_id = data["currency_id"]
        currency_rate = self.get_currency_rate(context)
        if price:
            if prod_cur_id:
                if prod_cur_id != currency_id:
                    cur_id=get_model("currency").browse(prod_cur_id)
                    currency_from_rate=cur_id.get_rate(date=data['date'],rate_type="buy") or 1
                    price = get_model("currency").convert(price, prod_cur_id, currency_id, from_rate=currency_from_rate, to_rate=currency_rate)
                else:
                    price = get_model("currency").convert(price, prod_cur_id, currency_id, to_rate=currency_rate)
            else:
                price = get_model("currency").convert(price, settings.currency_id.id, currency_id, to_rate=currency_rate)

        line["unit_price"] = price
        ratio = get_model("uom").browse(int(line["uom_id"])).ratio
        line["unit_price"] = price * ratio
        if prod.purchase_uom_id:
            line["unit_price"] = price * ratio / prod.purchase_uom_id.ratio or 1
        if prod.categ_id and prod.categ_id.purchase_tax_id:
            line["tax_id"] = prod.categ_id.purchase_tax_id.id
        if prod.purchase_tax_id is not None:
            line["tax_id"] = prod.purchase_tax_id.id
        contact_id=data.get('contact_id')
        if contact_id:
            contact=get_model("contact").browse(contact_id)
            if contact.tax_payable_id:
                line["tax_id"] = contact.tax_payable_id.id
        if data.get("tax_type","")=="no_tax":
            line["tax_id"]=None

        if prod.location_id:
            line["location_id"] = prod.location_id.id
        elif prod.locations:
            line["location_id"] = prod.locations[0].location_id.id
            #TODO
        #amount_cur
        self.onchange_location(context)
        data = self.update_amounts(context)
        return data
Exemple #28
0
 def update_cost(self, context={}):
     data = context["data"]
     path = context["path"]
     line = get_data_path(data, path, parent=True)
     line["total_cost"] = line['qty'] * line['unit_price']