Exemplo n.º 1
0
    def setUpClass(cls):
        super(TestRmaPurchase, cls).setUpClass()

        cls.rma_obj = cls.env['rma.order']
        cls.rma_line_obj = cls.env['rma.order.line']
        cls.rma_op_obj = cls.env['rma.operation']
        cls.rma_add_purchase_wiz = cls.env['rma_add_purchase']
        cls.po_obj = cls.env['purchase.order']
        cls.pol_obj = cls.env['purchase.order.line']
        cls.product_obj = cls.env['product.product']
        cls.partner_obj = cls.env['res.partner']

        cls.rma_route_cust = cls.env.ref('rma.route_rma_customer')

        # Create supplier
        supplier1 = cls.partner_obj.create({'name': 'Supplier 1'})

        # Create products
        cls.product_1 = cls.product_obj.create({
            'name': 'Test Product 1',
            'type': 'product',
        })
        cls.product_2 = cls.product_obj.create({
            'name': 'Test Product 2',
            'type': 'product',
        })

        # Create PO:
        cls.po = cls.po_obj.create({
            'partner_id': supplier1.id,
        })
        cls.pol_1 = cls.pol_obj.create({
            'name': cls.product_1.name,
            'order_id': cls.po.id,
            'product_id': cls.product_1.id,
            'product_qty': 20.0,
            'product_uom': cls.product_1.uom_id.id,
            'price_unit': 100.0,
            'date_planned': Datetime.now(),
        })
        cls.pol_2 = cls.pol_obj.create({
            'name': cls.product_2.name,
            'order_id': cls.po.id,
            'product_id': cls.product_2.id,
            'product_qty': 18.0,
            'product_uom': cls.product_2.uom_id.id,
            'price_unit': 150.0,
            'date_planned': Datetime.now(),
        })

        # Create RMA group:
        cls.rma_group = cls.rma_obj.create({
            'partner_id': supplier1.id,
            'type': 'supplier',
        })
Exemplo n.º 2
0
    def index(self, **kwargs):
        method = request.httprequest.method
        if method == "GET":
            return request.render("hr_sf.attendance_index")
        elif method == "POST":
            Attendance = request.env["hr.attendance"].sudo()
            Employee = request.env["hr.employee"].sudo()
            UploadLog = request.env["hr_sf.attendance_upload_log"].sudo()

            try:
                upload_file = kwargs.get("upload_file", None)
                source = kwargs.get("source", None)
                if upload_file is None:
                    raise Exception("can not get upload file from http post data")
                upload_file_content = upload_file.stream.read()
                sniffer = csv.Sniffer()
                dialect = sniffer.sniff(upload_file_content, delimiters=',\t')
                rows = csv.reader(upload_file_content.splitlines(), dialect=dialect)

                upload_log = None
                if rows:
                    base64_file = base64.standard_b64encode(upload_file_content)
                    upload_log = UploadLog.create({"upload_file": base64_file, "file_name": upload_file.filename,
                                                   "date": Datetime.now(), "source": source})
                upload_log_id = upload_log.id

                employees = Employee.search([])
                employee_ids = dict(employees.mapped(lambda r: (r.internal_code, r.id)))

                line_number = 0
                values = []
                for row in rows:
                    code, name, year, month, day, hour, minute = row[0:7]
                    location = str(int(row[7]))

                    dt_str = "%s-%s-%s %s:%s:00" % (year, month, day, hour, minute)
                    dt = Datetime.from_string(dt_str)
                    dt = dt - datetime.timedelta(hours=8)
                    odoo_dt_str = Datetime.to_string(dt)

                    exist_count = Attendance.search_count([("code", "=", code), ("name", "=", odoo_dt_str)])
                    if exist_count <= 0:
                        emp_id = employee_ids.get(code, None)
                        if emp_id is not None:
                            # Attendance.create({"employee_id": emp_id, "name": odoo_dt_str, "location": location,
                            #                    "action": "action", "upload_log_id": upload_log_id})
                            values.append({"employee_id": emp_id, "name": odoo_dt_str, "location": location,
                                           "action": "action", "upload_log_id": upload_log_id,
                                           "forget_card": False})
                        else:
                            raise Exception("error in line:%d,employee with code:%s not found" % (line_number, code))
                    line_number += 1

                for value in values:
                    Attendance.create(value)

                return request.render("hr_sf.attendance_upload_finish", {"import_count": len(values)})
            except Exception, e:
                request.env.cr.rollback()
                return e.message or e.value
Exemplo n.º 3
0
    def setUp(self):
        super(TestPurchaseOpenQty, self).setUp()
        self.purchase_order_model = self.env['purchase.order']
        purchase_order_line_model = self.env['purchase.order.line']
        partner_model = self.env['res.partner']
        prod_model = self.env['product.product']
        analytic_account_model = self.env['account.analytic.account']
        self.product_uom_model = self.env['product.uom']

        # partners
        pa_dict = {
            'name': 'Partner 1',
            'supplier': True,
        }
        self.partner = partner_model.sudo().create(pa_dict)
        pa_dict2 = {
            'name': 'Partner 2',
            'supplier': True,
        }
        self.partner2 = partner_model.sudo().create(pa_dict2)

        # account
        ac_dict = {
            'name': 'analytic account 1',
        }
        self.analytic_account_1 = \
            analytic_account_model.sudo().create(ac_dict)

        # Purchase Order Num 1
        po_dict = {
            'partner_id': self.partner.id,
        }
        self.purchase_order_1 = self.purchase_order_model.create(po_dict)
        uom_id = self.product_uom_model.search([
            ('name', '=', 'Unit(s)')])[0].id
        pr_dict = {
            'name': 'Product Test',
            'uom_id': uom_id,
            'purchase_method': 'purchase',
        }
        self.product = prod_model.sudo().create(pr_dict)

        pl_dict1 = {
            'date_planned': Datetime.now(),
            'name': 'PO01',
            'order_id': self.purchase_order_1.id,
            'product_id': self.product.id,
            'product_uom': uom_id,
            'price_unit': 1.0,
            'product_qty': 5.0,
            'account_analytic_id': self.analytic_account_1.id,
        }
        self.purchase_order_line_1 = \
            purchase_order_line_model.sudo().create(pl_dict1)
        self.purchase_order_1.button_confirm()

        # Purchase Order Num 2
        po_dict2 = {
            'partner_id': self.partner2.id,
        }
        self.purchase_order_2 = self.purchase_order_model.create(po_dict2)
        pr_dict2 = {
            'name': 'Product Test 2',
            'uom_id': uom_id,
            'purchase_method': 'receive',
        }
        self.product2 = prod_model.sudo().create(pr_dict2)
        pl_dict2 = {
            'date_planned': Datetime.now(),
            'name': 'PO02',
            'order_id': self.purchase_order_2.id,
            'product_id': self.product2.id,
            'product_uom': uom_id,
            'price_unit': 1.0,
            'product_qty': 5.0,
            'account_analytic_id': self.analytic_account_1.id,
        }
        self.purchase_order_line_2 = \
            purchase_order_line_model.sudo().create(pl_dict2)
        self.purchase_order_2.button_confirm()
Exemplo n.º 4
0
 def time_ago(from_):
     if from_ is None:
         from_ = Datetime.now()
     return human(Datetime.from_string(from_), 1)
Exemplo n.º 5
0
    def attendance_per_location(self, date=None, location=None):
        if not date:
            date = Date.today()

        dt_from = datetime.datetime.strptime("%s 00:00:00" % date, DEFAULT_SERVER_DATETIME_FORMAT) - datetime.timedelta(
                hours=8)
        dt_to = datetime.datetime.strptime("%s 23:59:59" % date, DEFAULT_SERVER_DATETIME_FORMAT) - datetime.timedelta(
                hours=8)

        if not location:
            location = "1"

        Attendance = request.env["hr.attendance"].sudo()
        Employee = request.env["hr.employee"].sudo()
        values = {}

        domain = []
        if date:
            domain.append(("name", ">=", Datetime.to_string(dt_from)))
            domain.append(("name", "<=", Datetime.to_string(dt_to)))

        # if location:
        #     domain.append(("location", "=", location))

        all_employees = Employee.search([])

        emp_attendances_values = []
        for emp in all_employees:
            attendance = dict()
            attendance["name"] = emp.name
            attendance["dep"] = emp.department_id.name

            records = Attendance.search(domain + [("employee_id", "=", emp.id)],
                                        order="name")
            if records and records[-1].location:
                latest_rec = records[-1]
                attendance["state"] = "打卡"

                dt = UTC_Datetime_To_TW_TZ(latest_rec.name)
                date_part = dt.strftime(DEFAULT_SERVER_DATE_FORMAT)
                time_part = dt.strftime(DEFAULT_SERVER_TIME_FORMAT)
                attendance["date"] = date_part
                attendance["time"] = time_part
                attendance["location"] = latest_rec.location
            else:
                attendance["state"] = "未打卡"
                attendance["date"] = None
                attendance["time"] = None
                attendance["location"] = None

            leave_time = emp.get_holiday_on(date)
            attendance["leave"] = string.join(leave_time.keys(), ",") if leave_time else None

            emp_attendances_values.append(attendance)

        # attendance_grouped_by_location = itertools.groupby(emp_attendances_values, key=lambda a: a["location"])
        attendances = defaultdict(lambda: list())
        for attendance in emp_attendances_values:
            attendances[attendance["location"]].append(attendance)  # or _("not attended")

        print_time = UTC_Datetime_To_TW_TZ(Datetime.now())
        values["print_time"] = Datetime.to_string(print_time)

        values["date"] = date
        values["location"] = location
        values["emp_attendances"] = attendances
        keys = sorted(attendances.keys())
        if None in keys:
            keys.remove(None)
            keys.append(None)
        values["attendance_keys"] = keys
        values["action_count"] = len(filter(lambda a: a.get("date", None), emp_attendances_values))
        values["un_action_count"] = len(filter(lambda a: not a.get("date", None), emp_attendances_values))

        return request.render("hr_sf.attendance_per_location", values)
Exemplo n.º 6
0
 def time_ago(from_):
     if from_ is None:
         from_ = Datetime.now()
     return human(Datetime.from_string(from_), 1)