← Back to team overview

openerp-connector-community team mailing list archive

Re: Odoo Magento Connector / Add a reordering rule for each imported product

 

On Thu, Sep 10, 2015 at 4:37 PM, Ahmad Ababneh <ababneh.a1@xxxxxxxxx> wrote:
> Hello,
>
> We need to add a default re-ordering rule for each imported product using
> the "Odoo Magento Connector". So, I guess I need to modify the "Product
> Import" behavior to achieve this.
>
> I created a module to customize the connector. Now, I am reading the
> following article for help
> (https://www.odoo.com/documentation/8.0/reference/orm.html#module-openerp.api
> )
>
> Under the CRUD section, it is mentioned that we can use "create(vals)"
> method to create a new record for the model.
>
> How can I use the "create(vals)" method in my custom module to create a
> re-ordering rule automatically after importing a product?
>
> Note: The stock_warehouse_orderpoint table is used to store the reordering
> rules.
>
> Thank you very much for your anticipated help.
>
> Best regards,
> Ahmed Ababneh
>
>


Hello,

you can extend the method _after_import of the ProductImporter
(https://github.com/OCA/connector-magento/blob/8.0/magentoerpconnect/product.py#L578)
which receives the imported binding as argument. The id of the product
is binding.openerp_id.id, so that you can do something like:

    def _after_import(self, binding):
        super(CustomProductImport, self)._after_import(binding)
        orderpoint_model = self.env['stock.warehouse.orderpoint']
        if not orderpoint_model.search([('product_id', '=',
binding.openerp_id.id), (...)]:
            orderpoint_model.create({'product_id':
binding.openerp_id.id, 'product_min_qty': x, ...})

Guewen


References