当前位置: 首页>>代码示例>>Python>>正文


Python model.get_model函数代码示例

本文整理汇总了Python中netforce.model.get_model函数的典型用法代码示例。如果您正苦于以下问题:Python get_model函数的具体用法?Python get_model怎么用?Python get_model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_model函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: validate

    def validate(self, ids, context={}):
        obj = self.browse(ids)[0]
        if not obj.lines:
            raise Exception("Product list is empty")
        pick = obj.picking_id
        if obj.mode == "backorder":
            vals = {
                "picking_id": pick.id,
                "lines": [],
            }
            for line in obj.lines:
                if not line.qty_actual:
                    raise Exception("Missing actual qty for product %s" % line.product_id.code)
                line_vals = {
                    "product_id": line.product_id.id,
                    "qty": line.qty_actual,
                    "uom_id": line.uom_id.id,
                }
                vals["lines"].append(("create", line_vals))
            val_id = get_model("pick.validate").create(vals)
            res = get_model("pick.validate").do_validate([val_id])
            obj.clear()
            return {
                "flash": res["flash"],
            }
        elif obj.mode == "loss":
            if not obj.location_loss_id:
                raise Exception("Missing inventory loss location")

            pick.set_done(context=context)  # XXX
            obj.clear()
            return {
                "flash": "Picking validated successfully",
                "focus_field": "picking_id",
            }
开发者ID:Sorawit123,项目名称:netforce,代码行数:35,代码来源:barcode_validate.py

示例2: reconcile

 def reconcile(self, ids, context={}):
     print("MoveLine.reconcile", ids)
     rec_id = get_model("account.reconcile").create({})
     all_ids = ids[:]
     for line in self.browse(ids):
         rec = line.reconcile_id
         if not rec:
             continue
         for rline in rec.lines:
             all_ids.append(rline.id)
     all_ids = list(set(all_ids))
     acc_id = None
     for obj in self.browse(all_ids):
         if not acc_id:
             acc_id = obj.account_id.id
         else:
             if obj.account_id.id != acc_id:
                 acc=get_model("account.account").browse(acc_id)
                 raise Exception("Can only reconcile transactions of same account (%s / %s)"%(obj.account_id.code,acc.code))
     self.write(all_ids, {"reconcile_id": rec_id})
     inv_ids=[]
     for obj in self.browse(all_ids):
         move=obj.move_id
         rel=move.related_id
         if rel._model=="account.invoice":
             inv_ids.append(rel.id)
     if inv_ids:
         get_model("account.invoice").function_store(inv_ids)
开发者ID:Sorawit123,项目名称:netforce,代码行数:28,代码来源:account_move_line.py

示例3: get_all_balances

def get_all_balances(date_from=None, date_to=None, track1=None, track2=None):
    t = time.time()
    k = (date_from, date_to, track1, track2)
    if k in _acc_bal_cache:
        res, res_t = _acc_bal_cache[k]
        if t - res_t <= 10:
            print("cache hit", k)
            return res
    print("cache miss", k)
    if track1:
        res = get_model("account.track.categ").search([["code", "=", track1]])
        if not res:
            raise Exception("Invalid tracking category: %s" % track1)
        track_id = res[0]
    else:
        track_id = None
    if track2:
        res = get_model("account.track.categ").search([["code", "=", track2]])
        if not res:
            raise Exception("Invalid tracking category: %s" % track2)
        track2_id = res[0]
    else:
        track2_id = None
    ctx = {
        "date_from": date_from,
        "date_to": date_to,
        "track_id": track_id,
        "track2_id": track2_id,
    }
    res = get_model("account.account").search_read([["type", "!=", "view"]], ["code", "balance"], context=ctx)
    _acc_bal_cache[k] = (res, t)
    return res
开发者ID:Sorawit123,项目名称:netforce,代码行数:32,代码来源:hbs_compiler.py

示例4: add_products

 def add_products(self, ids, context={}):
     obj = self.browse(ids)[0]
     pricelist = obj.pricelist_id
     categ_ids = [c.id for c in obj.product_categs]
     for prod in get_model("product").search_browse([["categs.id", "in", categ_ids]]):
         factor = pricelist.factor or 1.0
         if pricelist.base_price == "product":
             base_price = prod.sale_price or 0
         elif pricelist.base_price == "other_pricelist":
             if not pricelist.other_pricelist_id:
                 raise Exception("Missing base price list")
             base_price = get_model("price.list").get_price(
                 pricelist.other_pricelist_id.id, prod.id, 1) or 0  # XXX: qty
         elif pricelist.base_price == "volume":
             base_price = prod.volume or 0
         else:
             raise Exception("Invalid base price type")
         price = utils.round_amount(base_price * factor, pricelist.rounding, pricelist.rounding_method)
         vals = {
             "list_id": pricelist.id,
             "product_id": prod.id,
             "price": price,
         }
         get_model("price.list.item").create(vals)
     return {
         "next": {
             "name": "pricelist_item",
         },
         "flash": "Products added to price list",
     }
开发者ID:Sorawit123,项目名称:netforce,代码行数:30,代码来源:pricelist_add.py

示例5: compute_thai_tax

 def compute_thai_tax(self, context={}):
     emp_id = context.get("employee_id")
     if emp_id != 'null':
         emp_id = int(emp_id)
     emp = get_model("hr.employee").browse(emp_id)
     period = context.get("period", 12)
     date = context.get("date")
     vals = {}
     vals["B1"] = max(0, self.get_yearly_provident_fund(context=context) - 10000)
     #vals["B2"]=emp.gov_pension_fund or 0
     vals["B2"] = 0
     vals["B3"] = emp.teacher_fund or 0
     vals["B4"] = emp.old_disabled or 0
     vals["B5"] = emp.old_disabled_spouse or 0
     vals["B6"] = emp.severance_pay or 0
     vals["B7"] = vals["B1"] + vals["B2"] + vals["B3"] + vals["B4"] + vals["B5"] + vals["B6"]
     vals["C1"] = 30000
     vals["C2"] = 30000 if emp.spouse_filing_status in ("joint", "no_income") else 0
     vals["C3a"] = 15000 * (emp.num_child1 or 0)
     vals["C3b"] = 17000 * (emp.num_child2 or 0)
     vals["C4a"] = 30000 if emp.father_id_no else 0
     vals["C4b"] = 30000 if emp.mother_id_no else 0
     vals["C4c"] = 30000 if emp.spouse_father_id_no else 0
     vals["C4d"] = 30000 if emp.spouse_mother_id_no else 0
     vals["C5"] = emp.disabled_support or 0
     vals["C6"] = emp.parent_health_insurance or 0
     vals["C7"] = emp.life_insurance or 0
     vals["C8"] = min(10000, self.get_yearly_provident_fund(context=context))
     vals["C9"] = emp.retirement_mutual_fund or 0
     vals["C10"] = emp.long_term_equity_fund or 0
     vals["C11"] = emp.interest_residence or 0
     vals["C12"] = emp.other_deduct or 0
     vals["C13"] = self.get_yearly_social_security(context=context)
     vals["C14"] = vals["C1"] + vals["C2"] + vals["C3a"] + vals["C3b"] + vals["C4a"] + vals["C4b"] + vals["C4c"] + vals["C4d"] + \
         vals["C5"] + vals["C6"] + vals["C7"] + vals["C8"] + vals["C9"] + \
         vals["C10"] + vals["C11"] + vals["C12"] + vals["C13"]
     vals["A1"] = self.get_yearly_income(context=context) + vals["B6"]
     vals["A2"] = vals["B7"]
     vals["A3"] = vals["A1"] - vals["A2"]
     vals["A4"] = min(0.4 * vals["A3"], 60000)  # XXX: use settings
     vals["A5"] = vals["A3"] - vals["A4"]
     vals["A6"] = vals["C14"]
     vals["A7"] = vals["A5"] - vals["A6"]
     vals["A8"] = min(2 * (emp.education_donation or 0), 0.1 * vals["A7"])
     vals["A9"] = vals["A7"] - vals["A8"]
     vals["A10"] = min(emp.other_donation or 0, 0.1 * vals["A9"])
     vals["A11"] = vals["A9"] - vals["A10"]
     vals["A12"] = get_model("hr.tax.rate").compute_tax(vals["A11"])
     vals["A13"] = emp.house_deduct or 0
     vals["A14"] = max(0, vals["A12"] - vals["A13"])
     vals["A15"] = emp.wht_amount or 0
     vals["A16"] = vals["A14"] - vals["A15"]
     vals["A17"] = 0  # XXX
     vals["A18"] = 0
     vals["A19"] = 0
     vals["A20"] = vals["A16"]
     vals["A21"] = 0
     vals["A22"] = vals["A20"]
     vals["tax_month"] = vals["A12"] / period
     return vals
开发者ID:Sorawit123,项目名称:netforce,代码行数:60,代码来源:hr_payitem.py

示例6: get_categs

def get_categs(condition):
    print("get_categs")
    res=get_model("product").read_group(["categ_id"],condition=condition)
    categ_nums={}
    for r in res:
        categ_id=r["categ_id"][0] if r["categ_id"] else None
        categ_nums.setdefault(categ_id,0)
        categ_nums[categ_id]+=r["_count"]
    res=get_model("product.categ").search_read([],["code","name","parent_id"])
    categ_ids={}
    for r in res:
        categ_ids[r["id"]]=r
    top_categs=[]
    for r in res:
        parent_id=r["parent_id"][0] if r["parent_id"] else None
        if parent_id:
            parent=categ_ids[parent_id]
            parent.setdefault("sub_categories",[]).append(r)
        else:
            top_categs.append(r)
    for categ_id,num in categ_nums.items():
        if not categ_id:
            continue
        categ=categ_ids[categ_id]
        categ["num_products"]=num
    def _set_total_num(c):
        for s in c.get("sub_categories",[]):
            _set_total_num(s)
        if c.get("num_products") is None:
            c["num_products"]=0
        for s in c.get("sub_categories",[]):
            c["num_products"]+=s["num_products"]
    for c in top_categs:
        _set_total_num(c)
    return top_categs
开发者ID:jzoldyck,项目名称:netforce,代码行数:35,代码来源:ecom_products.py

示例7: check_sent_emails

 def check_sent_emails(self, context={}):
     print("send_sent_emails")
     res = get_model("email.account").search([["type", "=", "mailgun"]])  # XXX
     if not res:
         return
     acc_id = res[0]
     get_model("email.account").check_sent_emails([acc_id])
开发者ID:jzoldyck,项目名称:netforce,代码行数:7,代码来源:email_message.py

示例8: get_unit_price

 def get_unit_price(self,ids,context={}):
     settings=get_model("settings").browse(1)
     vals={}
     for obj in self.browse(ids):
         pick=obj.picking_id
         if pick:
             if pick.currency_rate:
                 currency_rate = pick.currency_rate
             else:
                 if pick.currency_id.id == settings.currency_id.id:
                     currency_rate = 1
                 else:
                     rate_from = pick.currency_id.get_rate(date=pick.date)
                     if not rate_from:
                         raise Exception("Missing currency rate for %s" % pick.currency_id.code)
                     rate_to = settings.currency_id.get_rate(date=pick.date)
                     if not rate_to:
                         raise Exception("Missing currency rate for %s" % settings.currency_id.code)
                     currency_rate = rate_from / rate_to
             price=obj.unit_price_cur or 0
             price_conv=get_model("currency").convert(price,pick.currency_id.id,settings.currency_id.id,rate=currency_rate)
         else:
             price_conv=None
         vals[obj.id]=price_conv
     return vals
开发者ID:bank-netforce,项目名称:netforce,代码行数:25,代码来源:stock_move.py

示例9: _get_loc_to

 def _get_loc_to(self, context={}):
     print("_get_loc_to", context)
     data = context.get("data")
     settings = get_model("settings").browse(1)
     if data:
         journal_id = data.get("journal_id")
         if journal_id:
             journal = get_model("stock.journal").browse(journal_id)
             if journal.location_to_id:
                 return journal.location_to_id.id
     pick_type = context.get("pick_type")
     pick_type = context.get("pick_type")
     if pick_type == "in":
         journal = settings.pick_in_journal_id
     elif pick_type == "out":
         journal = settings.pick_out_journal_id
     elif pick_type == "internal":
         journal = settings.pick_internal_journal_id
     else:
         journal = None
     if journal and journal.location_from_id:
         return journal.location_to_id.id
     if pick_type != "out":
         return None
     res = get_model("stock.location").search([["type", "=", "customer"]])
     if not res:
         return None
     return res[0]
开发者ID:bank-netforce,项目名称:netforce,代码行数:28,代码来源:stock_move.py

示例10: onchange_container

 def onchange_container(self, context={}):
     data = context["data"]
     cont_id = data.get("container_id")
     if not cont_id:
         return
     cont = get_model("stock.container").browse(cont_id)
     contents = cont.get_contents()
     lines = []
     for (prod_id, lot_id, loc_id), (qty, amt, qty2) in contents.items():
         prod = get_model("product").browse(prod_id)
         line_vals = {
             "product_id": prod_id,
             "qty": qty,
             "uom_id": prod.uom_id.id,
             "qty2": qty2,
             "location_from_id": loc_id,
             "location_to_id": None,
             "lot_id": lot_id,
             "container_from_id": cont_id,
         }
         if data["type"] == "internal":
             line_vals["container_to_id"] = cont_id
         lines.append(line_vals)
     data["lines"] = lines
     return data
开发者ID:bank-netforce,项目名称:netforce,代码行数:25,代码来源:stock_picking.py

示例11: update_cost_price

 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
开发者ID:bank-netforce,项目名称:netforce,代码行数:29,代码来源:stock_picking.py

示例12: to_draft

 def to_draft(self,ids,context={}):
     for obj in self.browse(ids):
         move_ids=[]
         for move in obj.lines:
             move_ids.append(move.id)
         get_model("stock.move").to_draft(move_ids)
         obj.write({"state":"draft"})
开发者ID:bank-netforce,项目名称:netforce,代码行数:7,代码来源:stock_picking.py

示例13: delete

 def delete(self, ids, **kw):
     move_ids = []
     for obj in self.browse(ids):
         for line in obj.lines:
             move_ids.append(line.id)
     get_model("stock.move").delete(move_ids)  # to update stored functions
     super().delete(ids, **kw)
开发者ID:bank-netforce,项目名称:netforce,代码行数:7,代码来源:stock_picking.py

示例14: make_po

 def make_po(self, ids, context={}):
     suppliers = {}
     for obj in self.browse(ids):
         if obj.qty_virt >= obj.min_qty:
             continue
         prod = obj.product_id
         if prod.supply_method!="purchase":
             raise Exception("Supply method for product %s is not set to 'Purchase'"%prod.code)
         res = get_model("stock.orderpoint").search([["product_id", "=", prod.id]])
         if res:
             op = get_model("stock.orderpoint").browse(res)[0]
             max_qty = op.max_qty
         else:
             max_qty = 0
         diff_qty = max_qty - obj.qty_virt
         if prod.purchase_uom_id:
             purch_uom=prod.purchase_uom_id
             if not prod.purchase_to_stock_uom_factor:
                 raise Exception("Missing purchase order -> stock uom factor for product %s"%prod.code)
             purch_qty=diff_qty/prod.purchase_to_stock_uom_factor
         else:
             purch_uom=prod.uom_id
             purch_qty=diff_qty
         if prod.purchase_qty_multiple:
             n=math.ceil(purch_qty/prod.purchase_qty_multiple)
             purch_qty=n*prod.purchase_qty_multiple
         if prod.purchase_uom_id:
             qty_stock=purch_qty*prod.purchase_to_stock_uom_factor
         else:
             qty_stock=None
         line_vals = {
             "product_id": prod.id,
             "description": prod.name_get()[0][1],
             "qty": purch_qty,
             "uom_id": purch_uom.id,
             "unit_price": prod.purchase_price or 0,
             "tax_id": prod.purchase_tax_id.id,
             "qty_stock": qty_stock,
         }
         if not prod.suppliers:
             raise Exception("Missing default supplier for product %s" % prod.name)
         contact_id = prod.suppliers[0].supplier_id.id
         suppliers.setdefault(contact_id, []).append(line_vals)
     if not suppliers:
         raise Exception("Nothing to order")
     count = 0
     for contact_id, lines in suppliers.items():
         vals = {
             "contact_id": contact_id,
             "lines": [("create", x) for x in lines],
         }
         purch_id = get_model("purchase.order").create(vals)
         count += 1
     return {
         "next": {
             "name": "purchase",
             "tab": "Draft",
         },
         "flash": "%d purchase orders created" % count,
     }
开发者ID:nfco,项目名称:netforce,代码行数:60,代码来源:stock_balance.py

示例15: create

 def create(self, vals, **kw):
     new_id = super().create(vals, **kw)
     inv_id = vals["invoice_id"]
     cred_id = vals["credit_id"]
     get_model("account.invoice").function_store([inv_id, cred_id])
     self.post([new_id])
     return new_id
开发者ID:jzoldyck,项目名称:netforce,代码行数:7,代码来源:account_credit_alloc.py


注:本文中的netforce.model.get_model函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。