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


Python access.get_active_company函数代码示例

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


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

示例1: get_report_data_custom

    def get_report_data_custom(self, ids, context={}):
        company_id = get_active_company()
        comp = get_model("company").browse(company_id)
        if ids:
            params = self.read(ids, load_m2o=False)[0]
        else:
            params = self.default_get(load_m2o=False, context=context)
        settings = get_model("settings").browse(1)
        date_from = params.get("date_from")
        date_to = params.get("date_to")
        d0 = datetime.strptime(date_from, "%Y-%m-%d")
        year_date_from = d0.strftime("%Y-01-01")  # XXX: get company fiscal year
        prev_date_from = (d0 - timedelta(days=1) - relativedelta(day=1)).strftime("%Y-%m-%d")
        prev_date_to = (d0 - timedelta(days=1) + relativedelta(day=31)).strftime("%Y-%m-%d")

        year_date_from_prev_year = (
            datetime.strptime(year_date_from, "%Y-%m-%d") - relativedelta(years=1)).strftime("%Y-%m-%d")
        date_from_prev_year = (datetime.strptime(date_from, "%Y-%m-%d") - relativedelta(years=1)).strftime("%Y-%m-%d")
        date_to_prev_year = (datetime.strptime(date_to, "%Y-%m-%d") - relativedelta(years=1)).strftime("%Y-%m-%d")

        data = {
            "date_from": date_from,
            "date_to": date_to,
            "year_date_from": year_date_from,
            "prev_date_from": prev_date_from,
            "prev_date_to": prev_date_to,
            "company_name": comp.name,
            "year_date_from_prev_year": year_date_from_prev_year,
            "date_from_prev_year": date_from_prev_year,
            "date_to_prev_year": date_to_prev_year,
        }
        print("data", data)
        return data
开发者ID:jzoldyck,项目名称:netforce,代码行数:33,代码来源:report_profit_loss.py

示例2: get_report_data

 def get_report_data(self, ids, context={}):
     company_id = get_active_company()
     company_ids = get_model("company").search([["id", "child_of", company_id]])
     comp = get_model("company").browse(company_id)
     if ids:
         params = self.read(ids, load_m2o=False)[0]
     else:
         params = self.default_get(load_m2o=False, context=context)
     settings = get_model("settings").browse(1)
     date_from = params.get("date_from")
     if not date_from:
         date_from = date.today().strftime("%Y-%m-01")
     date_to = params.get("date_to")
     if not date_to:
         date_to = (date.today() + relativedelta(day=31)).strftime("%Y-%m-%d")
     data = {
         "company_name": comp.name,
         "date_from": date_from,
         "date_to": date_to,
         "by_rate": params.get("by_rate"),
         "by_comp": params.get("by_comp"),
     }
     db = database.get_connection()
     if params.get("by_comp"):
         res = db.query("SELECT c.id AS comp_id,c.name AS comp_name,c.rate AS comp_rate,r.name AS rate_name,SUM(l.credit-l.debit) AS tax_total,SUM(l.tax_base*sign(l.credit-l.debit)) AS base_total FROM account_move_line l,account_move m,account_tax_component c,account_tax_rate r WHERE m.id=l.move_id AND m.state='posted' AND m.date>=%s AND m.date<=%s AND c.id=l.tax_comp_id AND r.id=c.tax_rate_id AND m.company_id IN %s GROUP BY comp_id,comp_name,comp_rate,rate_name ORDER BY comp_name,rate_name",
                        date_from, date_to, tuple(company_ids))
         data["comp_taxes"] = [dict(r) for r in res]
     if params.get("by_rate"):
         res = db.query("SELECT c.id AS comp_id,c.name AS comp_name,c.rate AS comp_rate,r.name AS rate_name,SUM(l.credit-l.debit) AS tax_total,SUM(l.tax_base*sign(l.credit-l.debit)) AS base_total FROM account_move_line l,account_move m,account_tax_component c,account_tax_rate r WHERE m.id=l.move_id AND m.state='posted' AND m.date>=%s AND m.date<=%s AND c.id=l.tax_comp_id AND r.id=c.tax_rate_id AND m.company_id IN %s GROUP BY comp_id,comp_name,comp_rate,rate_name ORDER BY rate_name,comp_name",
                        date_from, date_to, tuple(company_ids))
         data["rate_taxes"] = [dict(r) for r in res]
     return data
开发者ID:Sorawit123,项目名称:netforce,代码行数:32,代码来源:report_tax_sum.py

示例3: get_report_data

 def get_report_data(self, ids, context={}):
     if ids:
         params = self.read(ids, load_m2o=False)[0]
     else:
         params = self.default_get(load_m2o=False, context=context)
     company_id = get_active_company()
     comp = get_model("company").browse(company_id)
     settings = get_model("settings").browse(1)
     date_from = params.get("date_from")
     date_to = params.get("date_to")
     if not date_from:
         date_from = date.today().strftime("%Y-%m-01")
     if not date_to:
         date_to = (date.today() + relativedelta(day=31)).strftime("%Y-%m-%d")
     data = {
         "company_name": comp.name,
         "date_from": date_from,
         "date_to": date_to,
         "total_qty": 0,
         "total_amount": 0,
     }
     db = get_connection()
     res = db.query(
         "SELECT l.product_id,p.name AS product_name,p.sale_price AS product_price,SUM(l.amount) AS amount,SUM(l.qty) AS qty FROM account_invoice_line l,account_invoice i,product p WHERE i.id=l.invoice_id AND p.id=l.product_id AND i.date>=%s AND i.date<=%s GROUP BY l.product_id,p.name,p.sale_price ORDER BY p.name", date_from, date_to)
     lines = []
     for r in res:
         line = r
         line["avg_price"] = line["amount"] / line["qty"] if line["qty"] else None
         lines.append(line)
         data["total_qty"] += line["qty"]
         data["total_amount"] += line["amount"]
     data["lines"] = lines
     data["total_avg_price"] = data["total_amount"] / data["total_qty"] if data["total_qty"] else None
     pprint(data)
     return data
开发者ID:Sorawit123,项目名称:netforce,代码行数:35,代码来源:report_sale_product.py

示例4: get_rate

 def get_rate(self, ids, date=None, rate_type="buy", context={}):
     obj_id = ids[0]
     dbname = database.get_active_db()
     company_id = access.get_active_company()
     key = (dbname, company_id, obj_id, date, rate_type)
     if key in _cache and not context.get("no_cache"):
         return _cache[key]
     obj = self.browse(obj_id)
     res = None
     for rate in obj.rates:
         if rate.company_id.id != company_id:
             continue
         if date and rate.date > date:
             continue
         if rate_type == "buy":
             res = rate.buy_rate
             break
         else:
             res = rate.sell_rate
             break
     if res is None:
         for rate in obj.rates:
             if date and rate.date > date:
                 continue
             if rate_type == "buy":
                 res = rate.buy_rate
                 break
             else:
                 res = rate.sell_rate
                 break
     _cache[key] = res
     return res
开发者ID:analycer,项目名称:netforce,代码行数:32,代码来源:currency.py

示例5: money_out

 def money_out(self, context={}):
     company_id = get_active_company()
     company_ids = get_model("company").search([["id", "child_of", company_id]])
     db = get_connection()
     res = db.query(
         "SELECT COALESCE(l.due_date,l.move_date) AS due_date,SUM(l.credit-l.debit) as amount FROM account_move_line l JOIN account_account a ON a.id=l.account_id LEFT JOIN account_reconcile r ON r.id=l.reconcile_id WHERE l.move_state='posted' AND a.type='payable' AND l.reconcile_id IS NULL AND a.company_id IN %s GROUP BY COALESCE(l.due_date,l.move_date)",
         tuple(company_ids),
     )
     amounts = {}
     for r in res:
         amounts[r.due_date] = r.amount
     values = []
     d0 = date.today()
     d1 = d0 + timedelta(days=60)
     d = d0
     while d < d1:
         ds = d.strftime("%Y-%m-%d")
         values.append((js_time(d), amounts.get(ds, 0)))
         d += timedelta(days=1)
     data = {"value": [{"key": "Payable", "values": values}]}
     res = db.get(
         "SELECT count(*) AS count,SUM(amount_total_cur) AS amount FROM account_invoice WHERE type='in' AND inv_type='invoice' AND state='draft' AND company_id IN %s",
         tuple(company_ids),
     )
     if res:
         data["draft_count"] = res.count
         data["draft_amount"] = res.amount
     res = db.get(
         "SELECT count(*) AS count,SUM(amount_total_cur) AS amount FROM account_invoice WHERE type='in' AND inv_type='invoice' AND state='waiting_payment' AND due_date<now() AND company_id IN %s",
         tuple(company_ids),
     )
     if res:
         data["overdue_count"] = res.count
         data["overdue_amount"] = res.amount
     return data
开发者ID:jzoldyck,项目名称:netforce,代码行数:35,代码来源:report_payable.py

示例6: get_addresses

 def get_addresses(self,ids,context={}):
     vals={}
     comp_id=access.get_active_company()
     for obj in self.browse(ids):
         res=get_model("address").search([["settings_id","=",obj.id],["or",["company_id","=",None],["company_id","child_of",comp_id]]])
         vals[obj.id]=res
     return vals
开发者ID:Sorawit123,项目名称:netforce,代码行数:7,代码来源:settings.py

示例7: get_report_data

 def get_report_data(self, ids, context={}):
     company_id = get_active_company()
     comp = get_model("company").browse(company_id)
     if ids:
         params = self.read(ids, load_m2o=False)[0]
     else:
         params = self.default_get(load_m2o=False, context=context)
     settings = get_model("settings").browse(1)
     if not params.get("account_id"):
         return
     account_id = int(params.get("account_id"))
     date_from = params.get("date_from")
     date_to = params.get("date_to")
     if not date_from and not date_to:
         date_from = date.today().strftime("%Y-%m-01")
         date_to = (date.today() + relativedelta(day=31)).strftime("%Y-%m-%d")
     acc = get_model("account.account").browse(account_id, context={"date_to": date_to})
     acc_balance = acc.balance
     acc_unrec = get_model("account.account").browse(
         account_id, context={"date_to": date_to, "bank_rec_state": "not_reconciled"})
     unrec_paid_amt = acc_unrec.credit
     unrec_received_amt = acc_unrec.debit
     rec_paid = []
     condition = [["account_id", "=", account_id], ["move_id.state", "=", "posted"], ["move_id.date", ">=", date_from], [
         "move_id.date", "<=", date_to], ["state", "=", "reconciled"], ["credit", ">", 0]]
     for line in get_model("account.move.line").search_browse(condition, order="move_id.date,id"):
         vals = {
             "date": line.move_id.date,
             "description": line.description,
             "ref": line.move_id.number,
             "amount": line.credit - line.debit,
         }
         rec_paid.append(vals)
     rec_received = []
     condition = [["account_id", "=", account_id], ["move_id.state", "=", "posted"], ["move_id.date", ">=", date_from], [
         "move_id.date", "<=", date_to], ["state", "=", "reconciled"], ["debit", ">", 0]]
     for line in get_model("account.move.line").search_browse(condition, order="move_id.date,id"):
         vals = {
             "date": line.move_id.date,
             "description": line.description,
             "ref": line.move_id.number,
             "amount": line.debit - line.credit,
         }
         rec_received.append(vals)
     db = database.get_connection()
     data = {
         "company_name": comp.name,
         "date_from": date_from,
         "date_to": date_to,
         "account_name": acc.name,
         "rec_paid": rec_paid,
         "total_rec_paid": sum([l["amount"] for l in rec_paid]),
         "rec_received": rec_received,
         "total_rec_received": sum([l["amount"] for l in rec_received]),
         "acc_balance": acc_balance,
         "unrec_paid_amt": unrec_paid_amt,
         "unrec_received_amt": unrec_received_amt,
         "st_balance": acc_balance + unrec_paid_amt - unrec_received_amt,
     }
     return data
开发者ID:Sorawit123,项目名称:netforce,代码行数:60,代码来源:report_reconcile.py

示例8: debtor_exposure

 def debtor_exposure(self, context={}):
     company_id = get_active_company()
     company_ids = get_model("company").search([["id", "child_of", company_id]])
     db = get_connection()
     res = db.query(
         "SELECT p.id AS contact_id,p.name AS contact_name,SUM(amount_due_cur) AS amount_due FROM account_invoice i JOIN contact p ON p.id=i.contact_id WHERE i.type='out' AND i.inv_type='invoice' AND i.state='waiting_payment' AND i.company_id IN %s GROUP BY p.id,p.name ORDER BY amount_due DESC LIMIT 10", tuple(company_ids))
     data = [(r.contact_name, r.amount_due) for r in res]
     return {"value": data}
开发者ID:Sorawit123,项目名称:netforce,代码行数:8,代码来源:report_receivable.py

示例9: top_debtors

 def top_debtors(self, context={}):
     company_id = get_active_company()
     company_ids = get_model("company").search([["id", "child_of", company_id]])
     db = get_connection()
     res = db.query(
         "SELECT p.id AS contact_id,p.name AS contact_name,SUM(amount_due_cur) AS amount_due,SUM(CASE WHEN i.due_date<now()::date THEN amount_due_cur ELSE 0 END) AS amount_overdue FROM account_invoice i JOIN contact p ON p.id=i.contact_id WHERE i.type='out' AND i.inv_type='invoice' AND i.state='waiting_payment' AND i.company_id IN %s GROUP BY p.id,p.name ORDER BY amount_due DESC LIMIT 10", tuple(company_ids))
     data = [dict(r) for r in res]
     return data
开发者ID:Sorawit123,项目名称:netforce,代码行数:8,代码来源:report_receivable.py

示例10: post

 def post(self, ids, context={}):
     obj = self.browse(ids)[0]
     if obj.total_credit != obj.total_credit:
         raise Exception("Debit & Credit is not balance!")
     payrun = obj.payrun_id
     company_id = get_active_company()
     move = payrun.move_id
     if move:
         move.to_draft()
         for line in move.lines:
             line.delete()
     pst = get_model("hr.payroll.settings").browse(1)
     journal = pst.journal_id
     if not journal:
         raise Exception("Please define journal in payroll setting.")
     if not move:
         move_vals = {
             "journal_id": journal.id,
             "number": payrun.number,
             "date": payrun.date_pay,
             "narration": 'Paid-%s' % (payrun.date_pay),
             "related_id": "hr.payrun,%s" % payrun.id,
             "company_id": company_id,
         }
         move_id = get_model("account.move").create(move_vals)
         move = get_model("account.move").browse(move_id)
     lines = []
     for line in obj.lines:
         lines.append(('create', {
             'description': line.description or "",
             'debit': line.debit or 0,
             'credit': line.credit or 0,
             'account_id': line.account_id.id,
         }))
     move.write({
         'lines': lines,
     })
     # XXX
     for payslip in payrun.payslips:
         payslip.write({
             'move_id': move.id,
             'state': 'posted',
         })
     payrun.write({
         'move_id': move.id,
         'state': 'posted',
     })
     return {
         'next': {
             'name': 'payrun',
             'mode': 'form',
             'active_id': payrun.id,
         },
         'flash': 'payrun %s has been posted!' % payrun.number,
     }
开发者ID:Sorawit123,项目名称:netforce,代码行数:55,代码来源:payrun_journal.py

示例11: gen_payslips

    def gen_payslips(self, ids, context={}):
        print("gen_payslips", ids)
        obj = self.browse(ids)[0]
        date = obj.date_from
        emp_ids = get_model("hr.employee").search([["work_status", "=", "working"]])
        for emp in get_model("hr.employee").browse(emp_ids):
            period = 12
            res = get_model("hr.payslip").search([["run_id", "=", obj.id], ["employee_id", "=", emp.id]])
            # TODO: check if payslip exists already
            if res:
                continue
            vals = {
                "employee_id": emp.id,
                "date": date,
                "run_id": obj.id,
                'company_id': get_active_company(),
            }
            lines = []
            ctx = {
                "employee_id": emp.id,
                "date": date,
                "date_from": obj.date_from,
                "date_to": obj.date_to,
            }
            for item in get_model("hr.payitem").search_browse([]):  # XXX
                if item.tax_type == "thai":
                    ctx["year_income"] = (emp.salary or 0.0) * period

                qty, rate = item.compute(context=ctx)

                if not item.show_default:
                    continue

                line_vals = {
                    "payitem_id": item.id,
                    "qty": qty,
                    "rate": rate,
                }
                lines.append(line_vals)

            if emp.profile_id:
                lines = []
                for item in emp.profile_id.pay_items:
                    if item.tax_type == "thai":
                        ctx["year_income"] = (emp.salary or 0.0) * period
                    qty, rate = item.compute(context=ctx)
                    line_vals = {
                        "payitem_id": item.id,
                        "qty": qty,
                        "rate": rate,
                    }
                    lines.append(line_vals)

            vals["lines"] = [("create", line_vals) for line_vals in lines]
            get_model("hr.payslip").create(vals)
开发者ID:Sorawit123,项目名称:netforce,代码行数:55,代码来源:hr_payrun.py

示例12: get_company_currency

 def get_company_currency(self, ids, context={}):
     comp_cur = {}
     comp_id = get_active_company()
     for comp in get_model("company").search_browse([]):
         set_active_company(comp.id)
         comp_settings = get_model("settings").browse(1)
         comp_cur[comp.id] = comp_settings.currency_id.id
     set_active_company(comp_id)
     vals = {}
     for obj in self.browse(ids):
         vals[obj.id] = comp_cur.get(obj.company_id.id)
     return vals
开发者ID:jzoldyck,项目名称:netforce,代码行数:12,代码来源:account_account.py

示例13: get_report_data

 def get_report_data(self, ids, context={}):
     company_id = get_active_company()
     company_ids = get_model("company").search([["id", "child_of", company_id]])
     comp = get_model("company").browse(company_id)
     if ids:
         params = self.read(ids, load_m2o=False)[0]
     else:
         params = self.default_get(load_m2o=False, context=context)
     settings = get_model("settings").browse(1)
     company_name = comp.name
     contact_id = params.get("contact_id")
     if contact_id:
         contact_id = int(contact_id)
     date_from = params.get("date_from")
     date_to = params.get("date_to")
     show_details = params.get("show_details")
     db = get_connection()
     q = "SELECT l.id,m.date AS move_date,l.contact_id,p.name AS contact_name,m.number AS move_number,l.description,COALESCE(l.due_date,m.date) AS due_date,l.credit-l.debit AS total_amount,r.number AS reconcile_number,l.reconcile_id FROM account_move_line l JOIN account_account a ON a.id=l.account_id JOIN account_move m ON m.id=l.move_id LEFT JOIN contact p ON p.id=l.contact_id LEFT JOIN account_reconcile r ON r.id=l.reconcile_id WHERE l.move_state='posted' AND a.type='payable' AND a.company_id IN %s"
     args = [tuple(company_ids)]
     if date_from:
         q += " AND COALESCE(l.due_date,l.move_date)>=%s"
         args.append(date_from)
     if date_to:
         q += " AND COALESCE(l.due_date,l.move_date)<=%s"
         args.append(date_to)
     if contact_id:
         q += " AND l.contact_id=%s"
         args.append(contact_id)
     else:
         q += " AND l.contact_id IS NULL"  # XXX
     if not show_details:
         q += " AND (l.reconcile_id IS NULL OR r.balance!=0)"
     q += " ORDER BY COALESCE(l.due_date,m.date),l.id"
     res = db.query(q, *args)
     lines = []
     for r in res:
         vals = dict(r)
         if vals["reconcile_number"] and not vals["reconcile_number"].endswith("*"):
             vals["due_amount"] = 0
         else:
             vals["due_amount"] = vals["total_amount"]
         lines.append(vals)
     data = {
         "company_name": company_name,
         "date_from": date_from,
         "date_to": date_to,
         "lines": lines,
         "totals": {
             "amount_total": sum(l["due_amount"] for l in lines),
         }
     }
     return data
开发者ID:Sorawit123,项目名称:netforce,代码行数:52,代码来源:report_supp_invoice.py

示例14: get_report_data

 def get_report_data(self, ids, context={}):
     if ids:
         params = self.read(ids, load_m2o=False)[0]
     else:
         params = self.default_get(load_m2o=False, context=context)
     company_id = get_active_company()
     comp = get_model("company").browse(company_id)
     settings = get_model("settings").browse(1)
     date_from = params["date_from"]
     date_to = params["date_to"]
     contact_id = params.get("contact_id")
     account_id = params.get("account_id")
     data = {
         "company_name": comp.name,
         "date_from": date_from,
         "date_to": date_to,
     }
     cond = [["account_id.type", "in", ["cost_sales", "expense", "other_expense"]],
            ["move_id.date", ">=", date_from], ["move_id.date", "<=", date_to]]
     if contact_id:
         cond.append(["contact_id", "=", contact_id])
     if account_id:
         cond.append(["account_id", "=", account_id])
     groups = {}
     for obj in get_model("account.move.line").search_browse(cond, order="move_id.date"):
         line_vals = {
             "id": obj.id,
             "date": obj.move_id.date,
             "number": obj.move_id.number,
             "description": obj.description,
             "account_id": obj.account_id.id,
             "account_code": obj.account_id.code,
             "account_name": obj.account_id.name,
             "amount": obj.debit - obj.credit,
         }
         contact_id = obj.contact_id.id
         if contact_id in groups:
             group = groups[contact_id]
         else:
             group = {
                 "contact_id": contact_id,
                 "contact_name": obj.contact_id.name,
                 "lines": [],
             }
             groups[contact_id] = group
         group["lines"].append(line_vals)
     data["groups"] = sorted(groups.values(), key=lambda g: g["contact_name"] or "")
     for group in data["groups"]:
         group["total"] = sum([l["amount"] for l in group["lines"]])
     pprint(data)
     return data
开发者ID:Sorawit123,项目名称:netforce,代码行数:51,代码来源:report_account_purchase.py

示例15: payable_status

 def payable_status(self, context={}):
     company_id = get_active_company()
     company_ids = get_model("company").search([["id", "child_of", company_id]])
     data = {}
     for st in ("draft", "waiting_approval", "waiting_payment"):
         data[st] = {"count": 0, "amount": 0}
     db = get_connection()
     res = db.query(
         "SELECT state,COUNT(*) as count,SUM(amount_due_cur) as amount FROM account_invoice WHERE type='in' AND inv_type='invoice' AND company_id IN %s GROUP BY state",
         tuple(company_ids),
     )
     for r in res:
         data[r["state"]] = {"count": r["count"], "amount": r["amount"]}
     return data
开发者ID:jzoldyck,项目名称:netforce,代码行数:14,代码来源:report_payable.py


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