This question has been flagged

Hello everyone, i am trying to sync my Odoo application with an external app. When I import products pricelist with items by CSV, I need to then upload/sync the products pricelist item to this external app. For this, i need to overwrite the write method in Odoo, to perform the pricelist sync between odoo and external app.

However, when I run the Test Import, the write method is called anyways and so is my external upload method. Is there a way I can differ when the method are being called by a test or an actual import?


i've found the similiar question here: https://www.odoo.com/forum/help-1/question/differing-testing-import-and-actually-importing-143184

i've tried the similiar action but the return always False even im doing the real import, can you help me please?

result = super(ProductPricelistMBS, self.with_context(test_import=True)).write(values)
sync_import = self._context.get('test_import'False)
print(sync_import, "??????????????????????????????????????????????????")
Avatar
Discard
Author Best Answer

i found the answer, i need to do like this

class ImportInherit(models.TransientModel):
    _inherit = 'base_import.import'

    @api.multi
    def do(selffieldsoptionsdryrun=False):
        if 'test_import' not in self._context:
            res = super(ImportInherit, self).with_context(test_import=dryrun).do(fields, options, dryrun)
        else:
            res = super(ImportInherit, self).do(fields, options, dryrun)
        return res

then on my model check the context

result = super(ProductPricelistMBS, self).write(values)
test_import = self._context.get('test_import')
if not test_import:
    # statement to webhook external API
Avatar
Discard