This question has been flagged

I've added a new column in stock picking lines to the analytic account which used for journal entries related to this stock move but I should put it manually I need get its value from another analytic account field in production order while I made the order As done that what I've written to added analytic account to be added to journal entry form picking

class StockMove(models.Model):
_inherit = "stock.move"

analytic_account_id = fields.Many2one(
    string="Analytic Account", comodel_name="account.analytic.account",
)

def _prepare_account_move_line(
    self, qty, cost, credit_account_id, debit_account_id, description
):
    self.ensure_one()
    res = super(StockMove, self)._prepare_account_move_line(
        qty, cost, credit_account_id, debit_account_id, description
    )
    # Add analytic account in debit line
    if not self.analytic_account_id or not res:
        return res

    for num in range(0, 2):
        if (
            res[num][2]["account_id"]
            != self.product_id.categ_id.property_stock_valuation_account_id.id
        ):
            res[num][2].update({"analytic_account_id": self.analytic_account_id.id})
    return res

@api.model
def _prepare_merge_moves_distinct_fields(self):
    fields = super()._prepare_merge_moves_distinct_fields()
    fields.append("analytic_account_id")
    return fields


class StockMoveLine(models.Model):
_inherit = "stock.move.line"

analytic_account_id = fields.Many2one(related="move_id.analytic_account_id")

I've also added this field in production order

class MrpProduction(models.Model):
_inherit = 'mrp.production'

analytic_account_id = fields.Many2one(
    comodel_name='account.analytic.account', string='Analytic Account')

so how can I post the analytic account field from production order to stock picking line any help will be appreciated

Avatar
Discard