Esempio n. 1
0
    def make_diffs(self):
        from models import PayRecord, PayDiff
        from app import db

        prev_rex = self._get_previous_records()
        if not prev_rex:
            return
        for current_rec in self.records:
            qry = prev_rex.select().where(PayRecord.employee == current_rec.employee)
            if not qry.exists():
                continue
            rec_diffs = PayRecord.get_diffs(prev_rex.get(), current_rec)
            if rec_diffs:
                with db.atomic():
                    PayDiff.insert_many(rec_diffs).execute()
Esempio n. 2
0
    def make_diffs(self, prev_run_id):
        from app import db, diff_fields
        from models import PayDiff

        prev_rec = self._get_previous_record(prev_run_id)
        if not prev_rec:
            return

        diffs = []
        for field in diff_fields[3:]:
            curval = getattr(self, field)
            preval = getattr(prev_rec, field)
            if curval != preval:
                diffs.append({
                    'payrun': self.payrun,
                    'record': self,
                    'field_name': field,
                    'current_amount': curval,
                    'previous_amount': preval
                })
        if diffs:
            with db.atomic():
                PayDiff.insert_many(diffs).execute()