Exemplo n.º 1
0
class Profile(Model):
    _name = "profile"
    _string = "Profile"
    _key = ["name"]
    _fields = {
        "name": fields.Char("Name", required=True, search=True),
        "code": fields.Char("Short Code"),
        "perms": fields.One2Many("profile.access", "profile_id", "Model Permissions"),
        "field_perms": fields.One2Many("field.access", "profile_id", "Field Permissions"),
        "menu_perms": fields.One2Many("menu.access", "profile_id", "Menu Permissions"),
        "other_perms": fields.Many2Many("permission", "Other Permissions"),
        "home_action": fields.Char("Login Action"),
        "login_company_id": fields.Many2One("company", "Login Company"),
        "prevent_login": fields.Boolean("Prevent Login"),
        "comments": fields.One2Many("message", "related_id", "Comments"),
        "default_model_perms": fields.Selection([["full", "Full Access"], ["readonly","Read-only Access"], ["no", "No Access"]], "Default Model Permissions"),
        "default_menu_access": fields.Selection([["visible", "Visible"], ["hidden", "Hidden"]], "Default Menu Access"),
    }
    _order = "name"
    _defaults = {
        "default_model_perms": "full",
    }

    def get_data(self, context={}):
        vals = {}
        perms = []
        for m in get_model("model").search_browse([]):
            perms.append({
                "model_id": [m.id, m.string],
            })
        vals["perms"] = perms
        return vals

    def copy(self, ids, context={}):
        obj = self.browse(ids)[0]
        vals = {
            "name": obj.name + " (Copy)",
            "perms": [],
            "other_perms": [("set", [p.id for p in obj.other_perms])],
            "home_action": obj.home_action,
        }
        for perm in obj.perms:
            vals["perms"].append(("create", {
                "model_id": perm.model_id.id,
                "perm_read": perm.perm_read,
                "perm_create": perm.perm_create,
                "perm_write": perm.perm_write,
                "perm_delete": perm.perm_delete,
                "view_all": perm.view_all,
                "modif_all": perm.modif_all,
            }))
        profile_id = get_model("profile").create(vals)
        return {
            "next": {
                "name": "profile",
                "mode": "form",
                "active_id": profile_id,
            },
            "flash": "New profile created",
        }
Exemplo n.º 2
0
class JobLine(Model):
    _name = "job.line"
    _fields = {
        "job_id":
        fields.Many2One("job", "Job", required=True, on_delete="cascade"),
        "sequence":
        fields.Integer("Sequence"),
        "type":
        fields.Selection(
            [["labor", "Labor"], ["part", "Parts"], ["other", "Other"]],
            "Type"),
        "description":
        fields.Text("Description"),
        "product_id":
        fields.Many2One("product", "Product"),
        "qty":
        fields.Decimal("Qty"),
        "uom_id":
        fields.Many2One("uom", "UoM"),
        "unit_price":
        fields.Decimal("Sale Unit Price"),
        "amount":
        fields.Decimal("Sale Amount", function="get_amount"),
        "payment_type":
        fields.Selection([["contract", "Included In Contract"],
                          ["job", "Not Included In Contract"]],
                         "Payment Type"),
    }
    _order = "sequence,id"

    def get_amount(self, ids, context={}):
        vals = {}
        for obj in self.browse(ids):
            vals[obj.id] = (obj.qty or 0) * (obj.unit_price or 0)
        return vals
Exemplo n.º 3
0
class PaymentMethod(Model):
    _name = "payment.method"
    _string = "Payment Method"
    _fields = {
        "name":
        fields.Char("Name", required=True, search=True),
        "code":
        fields.Char("Code", search=True),
        "sequence":
        fields.Integer("Sequence"),
        "type":
        fields.Selection(
            [["bank", "Bank Transfer"], ["credit_card", "Credit Card"],
             ["paypal", "Paypal"], ["scb_gateway", "SCB Gateway"],
             ["paysbuy", "Paysbuy"]],
            "Type",
            search=True),
        "comments":
        fields.One2Many("message", "related_id", "Comments"),
        "account_id":
        fields.Many2One("account.account", "Account"),
        "paypal_url":
        fields.Selection(
            [["test", "Test URL"], ["production", "Production URL"]],
            "Server URL"),
        "paypal_user":
        fields.Char("Username", size=256),
        "paypal_password":
        fields.Char("Password", size=256),
        "paypal_signature":
        fields.Char("Signature", size=256),
        "paysbuy_id":
        fields.Char("Paysbuy ID"),
        "paysbuy_username":
        fields.Char("Username"),
        "paysbuy_securecode":
        fields.Char("Secure Code"),
        "paysbuy_resp_back_url":
        fields.Char("Response back URL"),
        "paysbuy_url":
        fields.Selection(
            [["test", "Test URL"], ["production", "Production URL"]],
            "Server URL"),
        "scb_mid":
        fields.Char("Merchant ID"),
        "scb_terminal":
        fields.Char("Terminal ID"),
        "scb_url":
        fields.Selection(
            [["test", "Test URL"], ["production", "Production URL"]],
            "Server URL"),
    }
    _order = "sequence,name"
Exemplo n.º 4
0
class Account(Model):
    _name = "email.account"
    _string = "Email Account"
    _name_field = "name"
    _fields = {
        "name":
        fields.Char("Account Name", required=True, search=True),
        "type":
        fields.Selection([["imap", "IMAP"], ["pop", "POP"], ["smtp", "SMTP"],
                          ["mailgun", "Mailgun"]],
                         "Type",
                         required=True,
                         search=True),
        "host":
        fields.Char("Host", required=True),
        "port":
        fields.Integer("Port"),
        "user":
        fields.Char("User"),
        "password":
        fields.Char("Password"),
        "security":
        fields.Selection([["starttls", "STARTTLS"], ["ssl", "SSL"]],
                         "Security"),
        "comments":
        fields.One2Many("message", "related_id", "Comments"),
        "mailboxes":
        fields.One2Many("email.mailbox", "account_id", "Mailboxes"),
    }

    def list_imap_mailboxes(self, ids, context={}):
        print("fetch_emails_imap", ids)
        obj = self.browse(ids)[0]
        if obj.type != "imap":
            raise Exception("Invalid email account type")
        if obj.security == "ssl":
            serv = imaplib.IMAP4_SSL(host=obj.host, port=obj.port or 993)
        else:
            serv = imaplib.IMAP4(host=obj.host, port=obj.port or 143)
        serv.login(obj.user, obj.password)
        res = serv.list()
        if res[0] != "OK":
            raise Exception("Invalid IMAP response")
        return {
            "next": {
                "name": "email_account",
                "mode": "form",
                "active_id": obj.id,
            },
            "flash":
            "Mailboxes found on IMAP server: " + ", ".join(m.decode()
                                                           for m in res[1]),
        }
Exemplo n.º 5
0
class BomLine(Model):
    _name = "bom.line"
    _fields = {
        "bom_id": fields.Many2One("bom", "BoM", required=True, on_delete="cascade"),
        "product_id": fields.Many2One("product", "Product", required=True),
        "qty": fields.Decimal("Qty", required=True, scale=6),
        "uom_id": fields.Many2One("uom", "UoM", required=True),
        "location_id": fields.Many2One("stock.location", "RM Warehouse"),
        "container": fields.Selection([["sale", "From Sales Order"]], "RM Container"),
        "lot": fields.Selection([["production", "From Production Order"]], "RM Lot"),
        "issue_method": fields.Selection([["manual", "Manual"], ["backflush", "Backflush"]], "Issue Method"),
        "qty2": fields.Decimal("Qty2", scale=6),
        "notes": fields.Text("Notes"),
    }
Exemplo n.º 6
0
class LinkListItem(Model):
    _name = "cms.linklist.item"
    _fields = {
        "list_id": fields.Many2One("cms.linklist", "Link List", required=True, on_delete="cascade"),
        "sequence": fields.Integer("Sequence"),
        "title": fields.Char("Title", required=True, translate=True),
        "type": fields.Selection([["menu", "Menu"], ["submenu", "Submenu"]], "Type", required=True),
        "url": fields.Char("URL", required=True, size=256),
        "sub_items": fields.One2Many("cms.linklist.item", None, "Sub Items", function="get_sub_items"),
    }
    _defaults = {
        "type": "menu",
    }
    _order = "list_id,sequence,id"

    def get_sub_items(self, ids, context={}):
        list_ids = []
        for obj in self.browse(ids):
            list_ids.append(obj.list_id.id)
        list_ids = list(set(list_ids))
        sub_items = {}
        for lst in get_model("cms.linklist").browse(list_ids):
            parent_id = None
            for item in lst.items:
                if item.type == "menu":
                    sub_items[item.id] = []
                    parent_id = item.id
                elif item.type == "submenu":
                    sub_items[parent_id].append(item.id)
        return {id: sub_items[id] for id in ids}
Exemplo n.º 7
0
class ProductionQC(Model):
    _name = "production.qc"
    _string = "Production Quality Control"
    _fields = {
        "order_id":
        fields.Many2One("production.order",
                        "Production Order",
                        required=True,
                        on_delete="cascade"),
        "test_id":
        fields.Many2One("qc.test", "QC Test", required=True),
        "sample_qty":
        fields.Decimal("Sampling Qty"),
        "value":
        fields.Char("Value"),
        "min_value":
        fields.Decimal("Min Value",
                       function="_get_related",
                       function_context={"path": "test_id.min_value"}),
        "max_value":
        fields.Decimal("Max Value",
                       function="_get_related",
                       function_context={"path": "test_id.max_value"}),
        "result":
        fields.Selection([["yes", "Pass"], ["no", "Not Pass"], ["na", "N/A"]],
                         "Result",
                         required=True),
    }
    _defaults = {
        "result": "no",
    }
class CustomOption(Model):
    _name = "product.custom.option"
    _string = "Custom Option"
    _key = ["code"]
    _fields = {
        "name":
        fields.Char("Name", required=True, search=True, translate=True),
        "seq":
        fields.Char("Sequence", required=True),
        "code":
        fields.Char("Code", search=True),
        "type":
        fields.Selection([["text", "Text"], ["selection", "Selection"]],
                         "Type",
                         required=True),
        "required":
        fields.Boolean("Required"),
        "description":
        fields.Text("Description"),
        "price":
        fields.Decimal("Price"),
        "values":
        fields.One2Many("product.custom.option.value", "cust_opt_id",
                        "Values"),
    }
    _defaults = {
        "type": "text",
        "seq": '0',
    }
Exemplo n.º 9
0
class Website(Model):
    _name = "website"
    _string = "Website"
    _fields = {
        "name": fields.Char("Website Title"),
        "parent_categ_id": fields.Many2One("product.categ", "Product Category"),
        "parent_group_id": fields.Many2One("product.group", "Product Group"),
        "contact_categ_id": fields.Many2One("contact.categ", "Customer Contact Category"),
        "user_profile_id": fields.Many2One("profile", "Customer User Profile"),
        "sale_account_id": fields.Many2One("account.account", "Sales Account"),
        "sale_tax_id": fields.Many2One("account.tax.rate", "Sales Tax"),
        "account_receivable_id": fields.Many2One("account.account", "Receivable Account"),
        "news_categ_id": fields.Many2One("contact.categ", "Newsletter Contact Category"),
        "target_list_id": fields.Many2One("mkt.target.list", "Newsletter Target List"),
        "invoice_flag": fields.Boolean("Use same invoice number as sale order number"),
        "ship_product_id": fields.Many2One("product", "Shipping Product"),
        "preview_doc_categ_id": fields.Many2One("document.categ", "Preview picture document category"),
        "invoice_template_id": fields.Many2One("report.template", "Invoice Template"),
        "payment_slip_template_id": fields.Many2One("report.template", "Payment Slip Template"),
        "auto_create_account": fields.Boolean("Auto-create customer account after checkout"),
        "ga_script": fields.Text("Google Analytic script"),
        "state": fields.Selection([["active", "Active"], ["inactive", "Inactive"]], "Status", required=True),
        "theme_id": fields.Many2One("theme", "Theme"),
        "settings": fields.One2Many("website.setting","website_id","Website Settings"),
        "sale_channel_id": fields.Many2One("sale.channel","Sales Channel"),
        "bank_method_id": fields.Many2One("payment.method","Bank Transfer",condition=[["type","=","bank"]]),
        "paypal_method_id": fields.Many2One("payment.method","Paypal",condition=[["type","=","paypal"]]),
        "paysbuy_method_id": fields.Many2One("payment.method","Paysbuy",condition=[["type","=","paysbuy"]]),
        "scb_method_id": fields.Many2One("payment.method","SCB Gateway",condition=[["type","=","scb_gateway"]]),
        "url": fields.Char("Website URL"),
    }
    _order="name"
    _defaults = {
        "state": "active",
    }
Exemplo n.º 10
0
class BarcodeQCLine(Model):
    _name = "barcode.qc.line"
    _transient = True
    _fields = {
        "barcode_id":
        fields.Many2One("barcode.qc",
                        "Barcode",
                        required=True,
                        on_delete="cascade"),
        "test_id":
        fields.Many2One("qc.test", "QC Test", required=True),
        "sample_qty":
        fields.Decimal("Sampling Qty", scale=6),
        "value":
        fields.Char("Value"),
        "min_value":
        fields.Decimal("Min Value",
                       function="_get_related",
                       function_context={"path": "test_id.min_value"}),
        "max_value":
        fields.Decimal("Max Value",
                       function="_get_related",
                       function_context={"path": "test_id.max_value"}),
        "result":
        fields.Selection([["yes", "Yes"], ["no", "No"], ["na", "N/A"]],
                         "Result",
                         required=True),
        "prod_qc_id":
        fields.Many2One("production.qc", "Production QC"),
    }
Exemplo n.º 11
0
class ScheduleLine(Model):
    _name = "hr.schedule.line"
    _string = "Schedule Line"

    def get_time_stop(self, ids, context={}):
        res = {}
        for obj in self.browse(ids):
            datenow = datetime.now().strftime("%Y-%m-%d")
            time_start = '%s %s' % (datenow, obj.time_start)
            time_total = obj.time_total or 0.0
            if obj.skip_mid:
                time_total += 1  # 12.00-13.00
            seconds = (time_total) * 60 * 60
            time_stop = datetime.strptime(time_start, '%Y-%m-%d %H:%S') + timedelta(seconds=seconds)
            res[obj.id] = time_stop.strftime("%H:%S")
        return res

    _fields = {
        'schedule_id': fields.Many2One("hr.schedule", "Schedule"),
        "dow": fields.Selection([["1", "Monday"], ["2", "Tuesday"], ["3", "Wednesday"], ["4", "Thursday"], ["5", "Friday"], ["6", "Saturday"], ["7", "Sunday"]], "Day Of Week"),
        'time_start': fields.Char("Time Start"),
        'time_stop': fields.Char("Time Stop"),
    }

    order = "dow, time_start"
Exemplo n.º 12
0
class EmailReject(Model):
    _name = "email.reject"
    _string = "Reject Email"
    _fields = {
        "email":
        fields.Char("Email", required=True, search=True),
        "reason":
        fields.Selection([["bounced", "Bounced"], ["rejected", "Rejected"],
                          ["unsubscribed", "Unsubscribed"],
                          ["complained", "Complained"], ["other", "Other"]],
                         "Reason",
                         search=True),
        "details":
        fields.Text("Details"),
        "date":
        fields.Date("Date Created", required=True, search=True),
    }
    _order = "date desc"
    _defaults = {
        "date": time.strftime("%Y-%m-%d %H:%M:%S"),
    }

    def add_to_black_list(self, email, reason):
        res = self.search([["email", "=", email]])
        if res:
            return
        vals = {
            "email": email,
            "reason": reason,
        }
        self.create(vals)
Exemplo n.º 13
0
class Rule(Model):
    _name = "wkf.rule"
    _string = "Workflow Rule"
    _name_field = "description"
    _fields = {
        "trigger_model_id":
        fields.Many2One("model", "Trigger Model", required=True, search=True),
        "trigger_event":
        fields.Char("Trigger Event", required=True, search=True),
        "condition_method":
        fields.Char("Condition Method"),
        "condition_args":
        fields.Text("Condition Arguments"),
        "action_model_id":
        fields.Many2One("model", "Action Model", required=True, search=True),
        "action_method":
        fields.Char("Action Method", required=True),
        "action_args":
        fields.Text("Action Arguments"),
        "description":
        fields.Text("Rule Description", search=True),
        "comments":
        fields.One2Many("message", "related_id", "Comments"),
        "state":
        fields.Selection([["active", "Active"], ["inactive", "Inactive"]],
                         "Status",
                         required=True,
                         search=True),
        "error":
        fields.Text("Error Message"),
    }
    _order = "trigger_model_id.name,trigger_event,action_model_id.name,action_method"
    _defaults = {
        "state": "active",
    }
Exemplo n.º 14
0
class Page(Model):
    _name = "cms.page"
    _string = "Page"
    _name_field = "title"
    _fields = {
        "title":
        fields.Char("Title", required=True, translate=True, search=True),
        "code":
        fields.Char("Code", required=True, search=True),
        "body":
        fields.Text("Body", translate=True),
        "blocks":
        fields.One2Many("cms.block", "related_id", "Blocks"),
        "comments":
        fields.One2Many("message", "related_id", "Comments"),
        "meta_description":
        fields.Char("Meta Description"),
        "meta_keywords":
        fields.Char("Meta Keywords"),
        "template":
        fields.Char("Template"),
        "state":
        fields.Selection([["active", "Active"], ["inactive", "Inactive"]],
                         "Status",
                         required=True),
    }
    _defaults = {
        "state": "active",
    }
Exemplo n.º 15
0
class FixedAssetType(Model):
    _name = "account.fixed.asset.type"
    _string = "Asset Type"
    _fields = {
        "name":
        fields.Char("Name", required=True, search=True),
        "dep_rate":
        fields.Decimal("Depreciation Rate (%)", search=True, required=True),
        "dep_method":
        fields.Selection(
            [["line", "Straight Line"], ["decline", "Declining Balance"]],
            "Depreciation Method",
            search=True,
            required=True),
        "fixed_asset_account_id":
        fields.Many2One("account.account",
                        "Fixed Asset Account",
                        required=True),
        "accum_dep_account_id":
        fields.Many2One("account.account",
                        "Accum. Depr. Account",
                        required=True),
        "dep_exp_account_id":
        fields.Many2One("account.account", "Depr. Exp. Account",
                        required=True),
        "description":
        fields.Text("Description"),
    }
Exemplo n.º 16
0
class StockOrderLine(Model):
    _name = "stock.order.line"
    _fields = {
        "order_id":
        fields.Many2One("stock.order",
                        "Order",
                        required=True,
                        on_delete="cascade"),
        "product_id":
        fields.Many2One("product", "Product", required=True),
        "qty":
        fields.Decimal("Order Qty", required=True),
        "uom_id":
        fields.Many2One("uom", "Order UoM", required=True),
        "date":
        fields.Date("Order Date", required=True),
        "supply_method":
        fields.Selection(
            [["purchase", "Purchase"], ["production", "Production"]],
            "Supply Method",
            function="_get_related",
            function_context={"path": "product_id.supply_method"}),
        "supplier_id":
        fields.Many2One("contact", "Supplier", function="get_supplier"),
    }

    def get_supplier(self, ids, context={}):
        vals = {}
        for obj in self.browse(ids):
            vals[obj.id] = obj.product_id.suppliers[
                0].supplier_id.id if obj.product_id.suppliers else None
        return vals
Exemplo n.º 17
0
class TranslationField(Model):
    _name = "translation.field"
    _fields = {
        "model": fields.Char("Model", required=True),
        "field": fields.Char("Field", required=True),
        "rec_id": fields.Integer("Record ID", required=True),
        "lang": fields.Selection([["zh_CN", "Chinese"], ["en_US", "English"], ["my_MM", "Myanmar"], ["th_TH", "Thai"]], "Language", required=True),
        "translation": fields.Text("Translation"),
    }
Exemplo n.º 18
0
class Bom(Model):
    _name = "bom"
    _string = "Bill of Material"
    _name_field = "number"
    _key = ["number"]
    _fields = {
        "number": fields.Char("Number", required=True, search=True),
        "product_id": fields.Many2One("product", "Product", required=True, search=True),
        "qty": fields.Decimal("Qty", required=True, scale=6),
        "uom_id": fields.Many2One("uom", "UoM", required=True),
        "location_id": fields.Many2One("stock.location", "FG Warehouse"),
        "routing_id": fields.Many2One("routing", "Routing"),
        "lines": fields.One2Many("bom.line", "bom_id", "Lines"),
        "comments": fields.One2Many("message", "related_id", "Comments"),
        "documents": fields.One2Many("document", "related_id", "Documents"),
        "max_qty_loss": fields.Decimal("Max Qty Loss", scale=6),
        "container": fields.Selection([["sale", "From Sales Order"]], "FG Container"),
        "lot": fields.Selection([["production", "From Production Order"]], "FG Lot"),
        "qc_tests": fields.Many2Many("qc.test", "QC Tests"),
    }

    def _get_number(self, context={}):
        while 1:
            num = get_model("sequence").get_number("bom")
            if not num:
                return None
            res = self.search([["number", "=", num]])
            if not res:
                return num
            get_model("sequence").increment("bom")

    _defaults = {
        "number": _get_number,
    }

    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
Exemplo n.º 19
0
class ReportTemplate(Model):
    _name = "report.template"
    _string = "Report Template"
    _multi_company = True
    _fields = {
        "name":
        fields.Char("Template Name", required=True, search=True),
        "type":
        fields.Selection(
            [["cust_invoice", "Customer Invoice"],
             ["cust_credit_note", "Customer Credit Note"],
             ["supp_invoice", "Supplier Invoice"], ["payment", "Payment"],
             ["account_move", "Journal Entry"], ["sale_quot", "Quotation"],
             ["sale_order", "Sales Order"], ["purch_order", "Purchase Order"],
             ["purchase_request", "Purchase Request"],
             ["prod_order", "Production Order"],
             ["goods_receipt", "Goods Receipt"],
             ["goods_transfer", "Goods Transfer"],
             ["goods_issue", "Goods Issue"], ["pay_slip", "Pay Slip"],
             ["tax_detail", "Tax Detail"], ["hr_expense", "HR Expense"],
             ["landed_cost", "Landed Cost"], ["other", "Other"]],
            "Template Type",
            required=True,
            search=True),
        "format":
        fields.Selection(
            [["odt", "ODT (old)"], ["odt2", "ODT"], ["ods", "ODS"],
             ["docx", "DOCX (old)"], ["xlsx", "XLSX"],
             ["jrxml", "JRXML (old)"], ["jrxml2", "JRXML"], ["jsx", "JSX"]],
            "Template Format",
            required=True,
            search=True),
        "file":
        fields.File("Template File"),
        "company_id":
        fields.Many2One("company", "Company"),
        "model_id":
        fields.Many2One("model", "Model"),
        "method":
        fields.Char("Method"),
    }
    _defaults = {
        "file_type": "odt",
    }
Exemplo n.º 20
0
class CopyDB(Model):
    _name = "copy_db"
    _store = False
    _fields = {
        "super_password": fields.Char("Super Admin Password", required=True),
        "dbname": fields.Selection([], "Database Name", required=True),
        "new_dbname": fields.Char("New Database Name", required=True),
    }

    def get_databases(self, context={}):
        db_list = sorted(database.list_databases())
        if config.get("sub_server"):
            request = context["request"]
            host = request.host
            i = host.find(".my.netforce.com")
            if i == -1:
                raise Exception("Invalid host")
            db_name = host[:i].replace("-", "_")
            db_list = [db_name]
        elif config.get("database"):
            db_list = [config.get("database")]
        return [(x, x) for x in db_list]

    def copy_db(self, context={}):
        data = context["data"]
        if data["super_password"] != config.get("super_password"):
            raise Exception("Invalid super admin password")
        dbname = data["dbname"]
        new_dbname = data["new_dbname"]
        print("copying db...")
        # database.close_connections(dbname);
        db = database.connect("template1")
        db._db.set_isolation_level(0)
        db.execute(
            "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname=%s",
            dbname)
        db.execute("CREATE DATABASE %s WITH TEMPLATE %s" %
                   (new_dbname, dbname))
        db.close()
        print("copying files...")
        fdir1 = os.path.join("static", "db", dbname, "files")
        if os.path.exists(fdir1):
            fdir2 = os.path.join("static", "db", new_dbname, "files")
            if not os.path.exists(fdir2):
                os.makedirs(fdir2)
            for f in os.listdir(fdir1):
                f1 = os.path.join(fdir1, f)
                f2 = os.path.join(fdir2, f)
                shutil.copy(f1, f2)
        return {
            "next": {
                "name": "login"
            },
            "flash": "Database copied successfully",
        }
Exemplo n.º 21
0
class Uom(Model):
    _name = "uom"
    _string = "Unit of Measure"
    _key = ["name"]
    _fields = {
        "name":
        fields.Char("Name", required=True, search=True),
        "type":
        fields.Selection(
            [["unit", "Unit"], ["time", "Time"], ["length", "Length"],
             ["weight", "Weight"], ["volume", "Volume"], ["other", "Other"]],
            "Type",
            required=True,
            search=True),
        "ratio":
        fields.Decimal("Ratio", required=True, scale=9),
        "comments":
        fields.One2Many("message", "related_id", "Comments"),
    }
    _defaults = {
        "ratio": 1,
    }

    def create(self, *a, **kw):
        new_id = super().create(*a, **kw)
        ipc.send_signal("clear_uom_cache")
        return new_id

    def write(self, *a, **kw):
        super().write(*a, **kw)
        ipc.send_signal("clear_uom_cache")

    def delete(self, *a, **kw):
        super().delete(*a, **kw)
        ipc.send_signal("clear_uom_cache")

    def get_ratio(self, uom_id, context={}):
        dbname = database.get_active_db()
        if not context.get("no_cache"):
            if (dbname, uom_id) in _cache:
                return _cache[(dbname, uom_id)]
        obj = self.browse(uom_id)
        if not context.get("no_cache"):
            _cache[(dbname, uom_id)] = obj.ratio
        return obj.ratio

    def convert(self, qty, uom_from_id, uom_to_id, context={}):
        #print("UoM.convert",qty,uom_from_id,uom_to_id)
        from_ratio = self.get_ratio(uom_from_id, context=context)
        #print("from_ratio",from_ratio)
        to_ratio = self.get_ratio(uom_to_id, context=context)
        #print("to_ratio",to_ratio)
        qty_conv = qty * (from_ratio or 1) / (to_ratio or 1)
        #print("qty_conv",qty_conv)
        return qty_conv
Exemplo n.º 22
0
class EcomProductReview(Model):
    _name = "ecom.product.review"
    _string = "Product Review"
    _fields = {
        "name":
        fields.Char("Name", required=True, search=True),
        "title":
        fields.Char("Title", required=True, search=True),
        "review":
        fields.Text("Review", required=True),
        "rating":
        fields.Selection([("0", "Not Rate"), ("1", "Bad"), ("2", "Poor"),
                          ("3", "Regular"), ("4", "Good"), ("5", "Gorgeous")],
                         "Rating"),
        "date":
        fields.DateTime("Date"),
        "state":
        fields.Selection([("draft", "Draft"), ("approved", "Approved"),
                          ("discarded", "Discarded")], "State"),
        "product_id":
        fields.Many2One("product", "Product", required=True, search=True),
    }
    _defaults = {
        "date": lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
        "state": "draft",
        "rating": "0"
    }
    _order = "date desc"

    def create(self, vals, **kw):
        id = super().create(vals, **kw)
        for obj in self.browse([id]):
            obj.trigger("created")

    def approve_review(self, ids, context={}):
        self.write(ids, {"state": "approved"})

    def reset_draft(self, ids, context={}):
        self.write(ids, {"state": "draft"})

    def discard_review(self, ids, context={}):
        self.write(ids, {"state": "discarded"})
class FixedAssetType(Model):
    _name = "account.fixed.asset.type"
    _string = "Asset Type"
    _fields = {
        "name":
        fields.Char("Name", required=True, search=True),
        "dep_rate":
        fields.Decimal("Depreciation Rate (%)", search=True, required=True),
        "dep_method":
        fields.Selection(
            [["line", "Straight Line"], ["decline", "Declining Balance"]],
            "Depreciation Method",
            search=True,
            required=True),
        "fixed_asset_account_id":
        fields.Many2One("account.account",
                        "Fixed Asset Account",
                        required=True,
                        multi_company=True),
        "accum_dep_account_id":
        fields.Many2One("account.account",
                        "Accum. Depr. Account",
                        required=True,
                        multi_company=True),
        "dep_exp_account_id":
        fields.Many2One("account.account",
                        "Depr. Exp. Account",
                        required=True,
                        multi_company=True),
        "description":
        fields.Text("Description"),
    }

    def copy(self, ids, context={}):
        obj = self.browse(ids)[0]
        vals = {
            'name': '%s (Copy)' % (obj.name),
            'dep_rate': obj.dep_rate,
            'dep_method': obj.dep_method,
            'fixed_asset_account_id': obj.fixed_asset_account_id.id,
            'accum_dep_account_id': obj.accum_dep_account_id.id,
            'dep_exp_account_id': obj.dep_exp_account_id.id,
            'description': obj.description,
        }
        new_id = self.create(vals)
        #new=self.browse(new_id)
        return {
            'next': {
                'name': "fixed_asset_type",
                "mode": "form",
                "active_id": new_id,
            },
            'flash': "Copy fixed asset type successfully!"
        }
Exemplo n.º 24
0
class BookstoreCustomer(Model):
    _name = "bookstore.customer"
    _fields = {
        "name":
        fields.Char("Name", required=True, size=256, search=True),
        "age":
        fields.Integer("Age", function="get_age"),
        "gender":
        fields.Selection([("male", "Male"), ("female", "Female")],
                         "Gender",
                         required=True),
        "job":
        fields.Char("Job"),
        "birth_date":
        fields.Date("Birth Date"),
        "num_of_book_burrowed":
        fields.Integer("Books Burrowed", function="get_num_of_book_burrowed"),
        "myfield":
        fields.Char("blabla"),
        "sijan_field":
        fields.Integer("Int"),
    }

    _defaults = {
        "birth_date": lambda *a: datetime.now().strftime("%Y-%m-%d"),
    }

    def get_age(self, ids, context={}):
        vals = {}
        for obj in self.browse(ids):

            date_string = obj.birth_date
            if date_string:
                date_obj = datetime.strptime(date_string, "%Y-%m-%d")
                today_obj = datetime.now()
                age = today_obj.year - date_obj.year
                vals[obj.id] = age
            else:
                vals[obj.id] = 0
        return vals

    def get_num_of_book_burrowed(self, ids, context={}):
        books = {}
        for obj in self.browse(ids):
            num = 0
            burrow_ids = get_model("bookstore.burrow").search(
                [["customer", "=", obj.id]])
            for j in burrow_ids:
                burrow = get_model("bookstore.burrow").browse(j)
                for line in burrow.lines:
                    num += line.qty
            books[obj.id] = num
        return books
Exemplo n.º 25
0
class Script(Model):
    _name = "script"
    _string = "Script"
    _key = ["name"]
    _fields = {
        "name": fields.Char("Name", required=True, search=True),
        "language": fields.Selection([["js", "Javascript"], ["py", "Python"]], "Language", required=True),
        "module_id": fields.Many2One("module", "Module"),
        "code": fields.Text("Code"),
    }
    _defaults = {
        "language": "js",
    }
    _order = "name"
Exemplo n.º 26
0
class TaxComponent(Model):
    _name = "account.tax.component"
    _fields = {
        "tax_rate_id":
        fields.Many2One("account.tax.rate",
                        "Tax Rate",
                        required=True,
                        on_delete="cascade"),
        "name":
        fields.Char("Name", required=True),
        "compound":
        fields.Boolean("Compound"),
        "rate":
        fields.Decimal("Rate", required=True),
        "account_id":
        fields.Many2One("account.account", "Account", multi_company=True),
        "type":
        fields.Selection(
            [["vat", "VAT"], ["vat_exempt", "VAT Exempt"],
             ["vat_defer", "Deferred VAT"], ["wht", "Withholding Tax"]],
            "Tax Type"),
        "trans_type":
        fields.Selection([["out", "Sale"], ["in", "Purchase"]],
                         "Transaction Type"),
        "description":
        fields.Text("Description"),
    }
    _defaults = {
        "rate": 0,
    }

    def name_get(self, ids, context={}):
        vals = []
        for obj in self.browse(ids):
            name = "%s - %s" % (obj.tax_rate_id.name, obj.name)
            vals.append((obj.id, name))
        return vals
Exemplo n.º 27
0
class Reminder(Model):
    _name = "reminder"
    _string = "Reminder"
    _fields = {
        "scheduled_date":
        fields.Date("Scheduled Date", required=True),
        "doc_id":
        fields.Many2One("document",
                        "Document",
                        required=True,
                        on_delete="cascade"),
        "user_id":
        fields.Many2One("base.user", "To User", required=True),
        "subject":
        fields.Char("Subject", required=True),
        "body":
        fields.Text("Body"),
        "state":
        fields.Selection([["pending", "Pending"], ["sent", "Sent"]],
                         "Status",
                         required=True),
    }
    _order = "scheduled_date,id"

    _defaults = {
        "scheduled_date": lambda *a: time.strftime("%Y-%m-%d"),
        "state": "pending",
    }

    def send_email(self, ids, context={}):
        for obj in self.browse(ids):
            to_addr = obj.user_id.email
            if not to_addr:
                continue
            vals = {
                "state": "to_send",
                "from_addr": "*****@*****.**",
                "to_addrs": to_addr,
                "subject": obj.subject,
                "body": obj.body,
            }
            get_model("email.message").create(vals)
            obj.write({"state": "sent"})

    def send_reminders(self):
        t = time.strftime("%Y-%m-%d")
        ids = self.search([["scheduled_date", "<=", t],
                           ["state", "=", "pending"]])
        self.send_email(ids)
Exemplo n.º 28
0
class ShareRecord(Model):
    _name = "share.record"
    _fields = {
        "related_id":
        fields.Reference([], "Related To"),
        "user_id":
        fields.Many2One("base.user", "User", required=True),
        "access":
        fields.Selection([["r", "Read Only"], ["rw", "Read/Write"]],
                         "Access",
                         required=True),
    }
    _defaults = {
        "access": "r",
    }
Exemplo n.º 29
0
class View(Model):
    _name = "view"
    _key = ["name"]
    _fields = {
        "name":
        fields.Char("Name", required=True),
        "model":
        fields.Char("Model"),
        "type":
        fields.Selection(
            [["list", "List"], ["form", "Form"], ["search", "Search"],
             ["m_list", "Mobile List"], ["m_form", "Mobile Form"],
             ["m_menu", "Mobile Menu"]], "Type"),
        "layout":
        fields.Text("Layout", required=True),
    }
Exemplo n.º 30
0
class Target(Model):
    _name = "mkt.target"
    _string = "Target"
    _name_field = "last_name"
    _fields = {
        "list_id": fields.Many2One("mkt.target.list", "Target List", required=True, on_delete="cascade"),
        "date": fields.Date("Date Created", required=True, search=True),
        "first_name": fields.Char("First Name", search=True),
        "last_name": fields.Char("Last Name", search=True),
        "company": fields.Char("Company", size=256, search=True),
        "email": fields.Char("Email", search=True),
        "street": fields.Char("Street"),
        "city": fields.Char("City"),
        "province_id": fields.Many2One("province", "Province", search=True),
        "zip": fields.Char("Zip"),
        "country_id": fields.Many2One("country", "Country", search=True),
        "phone": fields.Char("Phone"),
        "fax": fields.Char("Fax"),
        "mobile": fields.Char("Mobile"),
        "website": fields.Char("Website"),
        "birthday":  fields.Date("Birthday"),
        "target_life": fields.Integer("Target Life (days)", function="get_life"),
        "comments": fields.One2Many("message", "related_id", "Comments"),
        "email_status": fields.Selection([["error_syntax", "Syntax Error"], ["error_dns", "DNS Error"], ["error_smtp", "SMTP Error"], ["verified", "Verified"]], "Email Status", search=True, readonly=True),
        "email_error": fields.Text("Email Error Details", readonly=True),
    }
    _order = "date desc"
    _defaults = {
        "date": lambda *a: time.strftime("%Y-%m-%d"),
    }

    def name_get(self, ids, context={}):
        vals = []
        for obj in self.browse(ids):
            if obj.first_name:
                name = obj.first_name + " " + obj.last_name
            else:
                name = obj.last_name
            vals.append((obj.id, name))
        return vals

    def get_life(self, ids, context={}):
        vals = {}
        for obj in self.browse(ids):
            vals[obj.id] = (datetime.today() - datetime.strptime(obj.date, "%Y-%m-%d")).days if obj.date else None
        return vals