<commit_before># Copyright (C) 2021 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


from odoo import api, fields, models


class MrpWorkcenterProductivity(models.Model):
    _inherit = "mrp.workcenter.productivity"

    def _prepare_mrp_workorder_analytic_item(self):
        """
        Prepare additional values for Analytic Items created.
        For compatibility with analytic_activity_cost
        """
        self.ensure_one()
        return {
            "name": "{} / {}".format(self.production_id.name, self.workorder_id.name),
            "account_id": self.production_id.analytic_account_id.id,
            "date": fields.Date.today(),
            "company_id": self.company_id.id,
            "manufacturing_order_id": self.production_id.id,
            "workorder_id": self.workorder_id.id,
            "unit_amount": self.duration / 60,  # convert minutes to hours
            "amount": -self.duration / 60 * self.workcenter_id.costs_hour,
        }

    def generate_mrp_work_analytic_line(self):
        AnalyticLine = self.env["account.analytic.line"].sudo()
        for timelog in self:
            line_vals = timelog._prepare_mrp_workorder_analytic_item()
            analytic_line = AnalyticLine.create(line_vals)
            analytic_line.on_change_unit_amount()

    @api.model
    def create(self, vals):
        timelog = super().create(vals)
        if vals.get("date_end"):
            timelog.generate_mrp_work_analytic_line()
        return timelog

    def write(self, vals):
        if vals.get("date_end"):
            self.generate_mrp_work_analytic_line()
        res = super().write(vals)
        return res
<commit_msg>[FIX] mrp_account_analytic: workorder start/stop timer does not generate costs<commit_after># Copyright (C) 2021 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


from odoo import api, fields, models


class MrpWorkcenterProductivity(models.Model):
    _inherit = "mrp.workcenter.productivity"

    def _prepare_mrp_workorder_analytic_item(self):
        """
        Prepare additional values for Analytic Items created.
        For compatibility with analytic_activity_cost
        """
        self.ensure_one()
        return {
            "name": "{} / {}".format(self.production_id.name, self.workorder_id.name),
            "account_id": self.production_id.analytic_account_id.id,
            "date": fields.Date.today(),
            "company_id": self.company_id.id,
            "manufacturing_order_id": self.production_id.id,
            "workorder_id": self.workorder_id.id,
            "unit_amount": self.duration / 60,  # convert minutes to hours
            "amount": -self.duration / 60 * self.workcenter_id.costs_hour,
        }

    def generate_mrp_work_analytic_line(self):
        AnalyticLine = self.env["account.analytic.line"].sudo()
        for timelog in self:
            line_vals = timelog._prepare_mrp_workorder_analytic_item()
            analytic_line = AnalyticLine.create(line_vals)
            analytic_line.on_change_unit_amount()

    @api.model
    def create(self, vals):
        timelog = super().create(vals)
        if vals.get("date_end"):
            timelog.generate_mrp_work_analytic_line()
        return timelog

    def write(self, vals):
        res = super().write(vals)
        if vals.get("date_end"):
            self.generate_mrp_work_analytic_line()
        return res

{'fraction_non_alphanumeric': 0.10517191563132043, 'fraction_numerical': 0.005778676683039584, 'mean_word_length': 2.6213389121338913, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1551471', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1040, 'n_words': 198}