Job code price history

Hi guy, question…

Gat a crew code-price tracker implemented using Django and MySql
Job code change in a few weeks meaning certain task pay more while other pay less, what would be the easiest and best way to implement price history. Job codes are stored in a separate table from jobs.
Added code_price_history = FieldHistoryTracker(['code_price']) back in the day when app developed but not sure how to use it ::
If I update the code price with new price it will effect the entire year of job and not just the jobs after certain date, need some advice please.

class Job(models.Model):

    user = models.ForeignKey(
        Tech, on_delete=models.DO_NOTHING)

    JOB_TYPES = (
        ('wo', 'Work Order'),
        ('sc', 'Service Call')
    )

    work_order = models.CharField(max_length=64)
    job_type = models.CharField(max_length=16, choices=JOB_TYPES)
    address = models.CharField(max_length=256)
    customer_name = models.CharField(max_length=256)
    note = models.TextField(null=True, blank=True)
    codes = models.ManyToManyField(JobCode, through='JobCode')

    job_start = models.TimeField(null=True, blank=True)
    job_end = models.TimeField(null=True, blank=True)

    processed = models.BooleanField(null=True, blank=True)

    created_at = CustomDateTimeField(auto_now_add=True)
    updated_at = CustomDateTimeField(auto_now=True)

class JobCode(models.Model):
    code = models.CharField(max_length=4)
    code_type = models.CharField(max_length=32, default= '')
    code_description = models.CharField(max_length=256, default='')
    code_price = models.DecimalField(default=0, max_digits=6, decimal_places=2)
    code_link = models.URLField(max_length=256, default='')

    code_price_history = FieldHistoryTracker(['code_price'])

I am no sure what do you want to achieve, but if what you want is to keep track of the changes in your instance you cold use Django Simple History.

For example job code 565 paid $25 but from November 1 it will pay $26.50
All the contractor when they check their code tracker will get inaccurate sum for the year to date payouts as the previously submitted work orders code price will now reflect $26.50 even though the new price only effective from November 1st and onwards.

What we do for historical data is create a “History” table with a small number of key fields and one JSON field. We create the JSON field with all the data needed to recreate a particular invoice. There are no foreign keys or references to anything else. That way, those invoices remain static regardless of any changes to the rest of the system.

I think you should make other field with that information, one for the actual “market price” and another for the price you will pay to the contractor.

Almost every contractor got different rate, it was easy as I give each of them a rate %70-%95 what’s linked to the user profile than total * rate give them them payout.
I think this code need to look for the code_price_history (somehow)

def calculate_total(self):
        sum = 0
        for match in self.jobtbc_set.all(): 
            sum += round_half_up(float(match.posted_price * match.quantity) * (self.user.ratio / 100),2)  
        return sum