Esempio n. 1
0
    def __init__(self, enum_type, **kwargs):
        # 非必填项
        self.random = Random()
        self.enum_type = enum_type
        self.kwargs = kwargs

        self.time = arrow.now()

        # 名称
        self.telephone = Random(boolean_lower_case=False,
                                boolean_upper_case=False).return_sample(11)
        self.amount = self.kwargs.get("amount") or 999
        self.description = Random().return_sample(99)
        self.apply_body = {
            "utf8": "✓",
        }

        # 如果相同,可以与reject合并
        self.approve_body = {
            "utf8": "✓",
            "_method": "put",
            "key": self.singular,
            "%s[approve_description]" % self.singular: self.description,
        }

        self.revisit_body = {
            "utf8": "✓",

            # request_ticket:1c70d800-94e9-4946-b617-7c3225eee818

            # contacts_ids[]:
        }

        self.checkin_body = {
            "checkin": {
                "message": "",
                "checkin_name": "111",
                "address_attributes": {
                    "off_distance": 39,
                    "detail_address": "123",
                    "lng": 121.602001,
                    "lat": 31.200028
                }
            },
            "update_entity_address": False
        }

        self.setting_body = {
            "utf8": "✓",
            "_method": "put",
            "%s_approve[editable][enable]" % self.singular: "1",
            "%s_approve[editable][policy]" % self.singular: "can",
        }
Esempio n. 2
0
    def apply(self, str_csrf, user):
        # 每一次apply生成不同的title
        self.title = self.kwargs.get("title") or Random().return_sample(20)
        self.apply_body.update({
            "authenticity_token":
            str_csrf,
            "%s[is_draft]" % self.singular:
            False,
            "%s[name]" % self.singular:
            self.title,
            "%slead[address_attributes][tel]" % self.singular:
            self.telephone,
            "china_tag_id":
            4,
            "%s[address_attributes][country_id] % self.singular":
            4,
            "%s[user_id]" % self.singular:
            user.dto.id,
            "%s[want_department_id]" % self.singular:
            user.dto.departments[0].department.id,
        })
        if "status" in self.kwargs:
            self.apply_body["%s[status]" % self.singular] = EnumStatus[
                self.kwargs["status"]].value

        return self.apply_body
Esempio n. 3
0
    def apply(self, str_csrf, user):
        # 每一次apply生成不同的title
        self.title = self.kwargs.get("title") or Random().return_sample(20)
        self.apply_body.update({
            "authenticity_token":
            str_csrf,
            "%s[title]" % self.singular:
            self.title,
            "%s[total_amount]" % self.singular:
            self.amount,
            "%s[user_id]" % self.singular:
            user.dto.id,
            "%s[want_department_id]" % self.singular:
            user.dto.departments[0].department.id,
            "%s[contract_token]" % self.singular:
            user.session.csrf
        })
        if "approve_status" in self.kwargs:
            self.apply_body["%s[approve_status]" %
                            self.singular] = self.kwargs["approve_status"]
        if "sign_date" in self.kwargs:
            self.apply_body["%s[sign_date]" %
                            self.singular] = self.kwargs["sign_date"]
        if "start_at" in self.kwargs:
            self.apply_body["%s[start_at]" %
                            self.singular] = self.kwargs["start_at"]
        if "end_at" in self.kwargs:
            self.apply_body["%s[end_at]" %
                            self.singular] = self.kwargs["end_at"]

        return self.apply_body
Esempio n. 4
0
        def transfer(self, record, **kwargs):
            # 调拨
            self.number = Random().return_sample(17)
            self.quantity = record["基本数量"]
            self.date = record["单据日期"]
            self.from_warehouse, self.to_warehouse = [
                self.session.warehouse(wh) for wh in record["仓库"].split("=>")
            ]
            self.category = self.Category(kwargs["category"])
            self.session.product.get_detail()
            logging.info("创建%s:%s" % (self.category.name, self.number))
            self.session._set_head(
                HeaderFactory.Accept.ALL, HeaderFactory.ContentType.FORM,
                HeaderFactory.XCsrfToken.dynamic(self.session.csrf))
            url = "%s/api/%s.json" % (self.session._server.domain,
                                      self.category.apis)
            body = {
                "from_warehouse_id":
                self.from_warehouse.id,
                "to_warehouse_id":
                self.to_warehouse.id,
                "transferred_at":
                self.date,
                "total_quantity":
                self.quantity,
                "number":
                self.number,
                # 允许库存不足
                "allow_negative_inventory":
                "true",
                "status":
                "approving",
                "product_items_attributes[0][product_attr_group_id]":
                self.session.product.detail["product_attr_groups"][0]["id"],
                "product_items_attributes[0][product_id]":
                self.session.product.id,
                "product_items_attributes[0][product_unit_id]":
                self.session.product.detail["product_units"][0]["id"],
                "product_items_attributes[0][name]":
                self.session.product.name,
                "product_items_attributes[0][product_number]":
                self.session.product.number,
                "product_items_attributes[0][unit]":
                "坨",
                "product_items_attributes[0][quantity]":
                self.quantity,
                "product_items_attributes[0][modified]":
                "quantity"
            }

            self.id = self.session.post(url, body=body).as_json(
                "storage_transfer", "id").get()

            return self
Esempio n. 5
0
        def package(self, record, **kwargs):
            self.number = Random().return_sample(17)
            self.quantity = record["基本数量"]
            self.date = record["单据日期"]
            # category.status:
            # 0:组装入库:product:成品;excipient:配件
            # 1:组装出库:product:配件;excipient:成品
            # 2:拆装入库:product:配件;excipient:成品
            # 3:拆装出库:product:成品;excipient:配件
            self.category = self.Category(kwargs["category"])
            # 组装入库/拆装出库
            if self.category.status in [0, 3]:
                self.finished_item = self.session.product
                self.part_items = self.session.excipient
            else:
                self.finished_item = self.session.excipient
                self.part_items = self.session.product

            # 如果输入单价==0,则为出库单
            # 出库单以主产品的当前统计价格为准
            self.unit_cost = record["单价"] or self.session.product.get_detail(
            ).detail["product_attr_groups"][0]["unit_cost"]
            self.warehouse = self.session.warehouse(record["仓库"])
            self.total_cost = self.unit_cost * self.quantity
            self.session.product.get_detail()
            logging.info("创建%s:%s" % (self.category.name, self.number))
            self.session._set_head(
                HeaderFactory.Accept.ALL, HeaderFactory.ContentType.FORM,
                HeaderFactory.XCsrfToken.dynamic(self.session.csrf))
            url = "%s/%s.json" % (self.session._server.domain,
                                  self.category.apis)
            body = {
                "%s[number]" % self.category.api: self.number,
                "%s[date]" % self.category.api: self.date,
                "%s[cost]" % self.category.api: 0.00,
                "%s[total_quantity]" % self.category.api: self.quantity,
                "%s[total_cost]" % self.category.api: self.total_cost,
                "%s[status]" % self.category.api: "approving",
                # 允许库存不足
                "%s[allow_negative_inventory]" % self.category.api: "true",
                "%s[fifo_total_cost]" % self.category.api: self.total_cost,
            }

            body.update(self.__package_attributes(True))
            body.update(self.__package_attributes(False))

            self.id = self.session.post(url, body=body).as_json(
                self.category.api, "id").get()

            return self
Esempio n. 6
0
        def approve(self):
            # 审批出入库单
            logging.info("审批%s:%s" % (self.category.name, self.number))
            self.session._set_head(
                HeaderFactory.Accept.ALL, HeaderFactory.ContentType.FORM,
                HeaderFactory.XCsrfToken.dynamic(self.session.csrf))
            url = "%s/api/%s/%s.json" % (self.session._server.domain,
                                         self.category.apis, self.id)
            body = {
                "status": "approving",
                "approved_level": 1,
                "reason": Random().return_sample(99),
                "allow_negative_inventory": "true"
            }

            self.session.put(url, body=body)
            return self
Esempio n. 7
0
    def apply(self, str_csrf, user):
        # 每一次apply生成不同的title
        self.title = self.kwargs.get("title") or Random().return_sample(20)
        self.apply_body.update({
            "authenticity_token":
            str_csrf,
            "%s[name]" % self.singular:
            self.title,
            "%s[user_id]" % self.singular:
            user.dto.id,
            "%s[want_department_id]" % self.singular:
            user.dto.departments[0].department.id,
            "%s[customer_token]" % self.singular:
            user.session.csrf,
        })
        if "approve_status" in self.kwargs:
            self.apply_body["%s[approve_status]" %
                            self.singular] = self.kwargs["approve_status"]

        return self.apply_body
Esempio n. 8
0
        def create(self, record, name=None):
            self.quantity = record["基本数量"]
            self.date = record["单据日期"]
            self.unit_cost = record["单价"]
            self.warehouse = self.session.warehouse(record["仓库"])
            self.total_cost = self.unit_cost * self.quantity
            # 产品编号/名称
            self.number = Random().return_sample(17)
            self.name = name if name else self.number

            logging.info("创建产品:%s" % self.number)
            self.session._set_head(HeaderFactory.Accept.ALL,
                                   HeaderFactory.ContentType.JSON)
            self.session.set_authorization(token=self.session.token,
                                           uid=self.session.uid)
            url = "%s/api/v1/products.json" % self.session._server.domain
            body = {
                "product": {
                    "number":
                    self.number,
                    "name":
                    self.name,
                    "product_category_id":
                    self.product_category_id,
                    "spec":
                    "",
                    "note":
                    "",
                    "barcode":
                    "",
                    "default_unit_id":
                    self.default_unit_id,
                    "default_in_unit_id":
                    self.default_unit_id,
                    "current_warning_policy":
                    "no_warning",
                    "split_warning_status":
                    "split_closed",
                    "total_warning_status":
                    "total_closed",
                    "attr_warning_status":
                    "attr_warning_closed",
                    "unit_setting":
                    "single_unit",
                    "batch_status":
                    "batch_closed",
                    "serial_code_status":
                    "serial_closed",
                    "attr_status":
                    "attr_closed",
                    "purchase_price_setting":
                    "purchase_simple_price",
                    "sale_price_setting":
                    "sale_simple_price",
                    "product_units_attributes": [{
                        "unit_id": self.default_unit_id,
                        "unit_name": "坨",
                        "conversion": 1
                    }],
                    "product_attr_groups_attributes": [{
                        "category":
                        "default_attr",
                        "product_attr_names":
                        "",
                        "product_attr_ids":
                        "",
                        "number":
                        "",
                        "simple_prices_attributes": [],
                        "default_inventory_policies_attributes": []
                    }]
                }
            }
            if self.quantity:
                body["product"]["product_attr_groups_attributes"][0][
                    "default_inventory_policies_attributes"].append({
                        "warehouse_id":
                        self.warehouse.id,
                        "warehouse_name":
                        self.warehouse.name,
                        "default_quantity":
                        self.quantity,
                        "default_unit_cost":
                        self.unit_cost,
                        "default_cost":
                        self.total_cost
                    })
            # 发送请求,并从响应中获取id
            self.id = self.session.post(url, body=body).as_json(
                "data", "product", "id").get()
            return self.get_detail()
Esempio n. 9
0
        def storageio(self, record, **kwargs):
            # 调拨
            self.number = Random().return_sample(17)
            self.quantity = record["基本数量"]
            self.date = record["单据日期"]
            self.unit_cost = record["单价"]
            self.warehouse = self.session.warehouse(record["仓库"])
            self.total_cost = self.unit_cost * self.quantity

            self.category = self.Category(kwargs["category"])
            self.session.product.get_detail()
            logging.info("创建%s:%s" % (self.category.name, self.number))
            self.session._set_head(
                HeaderFactory.Accept.ALL, HeaderFactory.ContentType.FORM,
                HeaderFactory.XCsrfToken.dynamic(self.session.csrf))
            url = "%s/api/%s.json" % (self.session._server.domain,
                                      self.category.apis)
            body = {
                "number":
                self.number,
                "total_quantity":
                self.quantity,
                "total_base_quantity":
                "",
                "total_amount":
                self.total_cost,
                "storaged_at":
                self.date,
                "storageio_category_id":
                self.category.id,
                "check_id":
                "",
                "status":
                "approving",
                "product_items_attributes[0][product_attr_group_id]":
                self.session.product.detail["product_attr_groups"][0]["id"],
                "product_items_attributes[0][product_id]":
                self.session.product.id,
                "product_items_attributes[0][product_unit_id]":
                self.session.product.detail["product_units"][0]["id"],
                "product_items_attributes[0][warehouse_id]":
                self.warehouse.id,
                "product_items_attributes[0][name]":
                self.session.product.name,
                "product_items_attributes[0][product_number]":
                self.session.product.number,
                "product_items_attributes[0][attr_names]":
                "",
                "product_items_attributes[0][spec]":
                "",
                "product_items_attributes[0][unit]":
                "坨",
                "product_items_attributes[0][quantity]":
                self.quantity,
                "product_items_attributes[0][price]":
                self.unit_cost,
                "product_items_attributes[0][amount]":
                self.total_cost,
                "product_items_attributes[0][note]":
                "",
                "product_items_attributes[0][batch_number]":
                "",
                "product_items_attributes[0][produced_at]":
                "",
                "product_items_attributes[0][expired_at]":
                "",
                "product_items_attributes[0][modified]":
                "quantity",
                "product_items_attributes[0][position]":
                0,
                # 允许库存不足
                "allow_negative_inventory":
                "true"
            }

            self.id = self.session.post(url,
                                        body=body).as_json("storageio",
                                                           "id").get()

            return self
Esempio n. 10
0
        def apply(self, record, **kwargs):
            # 提交销售单
            # 产品编号/名称
            self.number = Random().return_sample(17)
            self.quantity = record["基本数量"]
            self.date = record["单据日期"]
            self.unit_cost = record["单价"]
            self.warehouse = self.session.warehouse(record["仓库"])
            self.total_cost = self.unit_cost * self.quantity

            self.category = self.Category(kwargs["category"])
            self.session.product.get_detail()
            logging.info("创建%s:%s" % (self.category.name, self.number))
            self.session._set_head(
                HeaderFactory.Accept.ALL, HeaderFactory.ContentType.FORM,
                HeaderFactory.XCsrfToken.dynamic(self.session.csrf))
            url = "%s/api/sales.json" % self.session._server.domain
            body = {
                "customer_id":
                EnumCustomer.张海艳.value,
                "seller_id":
                EnumSeller.施亮赜.value,
                "contact_id":
                self.contact_id,
                "category":
                self.category.category,
                "number":
                self.number,
                "io_at":
                self.date,
                "discount":
                0.00,
                "deduction":
                0.00,
                "amount":
                self.total_cost,
                "contact_name":
                "一头烧鸭",
                "contact_mobile":
                "13681876857",
                "contact_address":
                "长白山云顶天宫大铜门",
                "supplier_address":
                "塔克拉玛干精绝古城九层妖塔",
                "total_quantity":
                self.quantity,
                "total_deduction":
                0.00,
                "total_amount":
                self.total_cost,
                "total_tax_amount":
                0.00,
                "total_amount_with_tax":
                self.total_cost,
                "status":
                "approving",
                "product_items_attributes[0][product_attr_group_id]":
                self.session.product.detail["product_attr_groups"][0]["id"],
                "product_items_attributes[0][product_id]":
                self.session.product.id,
                "product_items_attributes[0][warehouse_id]":
                self.warehouse.id,
                "product_items_attributes[0][product_unit_id]":
                self.session.product.detail["product_units"][0]["id"],
                "product_items_attributes[0][name]":
                self.session.product.name,
                "product_items_attributes[0][product_number]":
                self.session.product.number,
                "product_items_attributes[0][unit]":
                "坨",
                "product_items_attributes[0][quantity]":
                self.quantity,
                "product_items_attributes[0][price]":
                self.unit_cost,
                "product_items_attributes[0][price_with_tax]":
                self.unit_cost,
                "product_items_attributes[0][discount]":
                0.00,
                "product_items_attributes[0][deduction]":
                0.00,
                "product_items_attributes[0][amount]":
                self.total_cost,
                "product_items_attributes[0][tax_rate]":
                0.00,
                "product_items_attributes[0][tax_amount]":
                0.00,
                "product_items_attributes[0][amount_with_tax]":
                self.total_cost,
                "product_items_attributes[0][modified]":
                self.category.modified,
                "product_items_attributes[0][position]":
                0,
                # 允许库存不足
                "allow_negative_inventory":
                "true"
            }

            self.id = self.session.post(url, body=body).as_json("sale",
                                                                "id").get()

            return self