OCA / connector-magento

Connect Odoo with Magento
http://odoo-magento-connector.com/
GNU Affero General Public License v3.0
105 stars 207 forks source link

[Feature] Sales Order Salesperson #63

Open dfrankland opened 10 years ago

dfrankland commented 10 years ago

Salesperson in Sales Orders (sale.order.user_id) should be set as the customer's Salesperson (res.partner.user_id) on imported orders.

I know that other salespeople will not be able to see the orders then according to https://github.com/OCA/connector-magento/blob/7.0/magentoerpconnect/sale.py#L964-L968:

@mapping
    def user_id(self, record):
        """ Do not assign to a Salesperson otherwise sales orders are hidden
        for the salespersons (access rules)"""
        return {'user_id': False}

But, this is necessary for accounting and commission of salespeople, so maybe this should be configurable setting.

If anyone can also give a little direction as to how to proceed with this issue I can make a pull request.

guewen commented 9 years ago

Hi @dukedylan,

If the partner has a sales person, it could make sense to assign it to its new orders. I don't want to add an option for every single detail though. So either we consider it is sufficiently generic (here I tend to think yes), either it should be done in a customization module.

You will have to modify the user_id mapping, the partner of the sale order is in self.options.partner_id, so you could modify it this way:

@mapping
def user_id(self, record):
    """ Assign the salesperson of the partner if any """
    if self.options.partner_id.user_id:
        return {'user_id': self.options.partner_id.user_id.id}
    return {'user_id': False}
yostashiro commented 9 years ago

Since self.options.partner_id is just an integer, the code should be like below:

    @mapping
    def user_id(self, record):
        """ Assign the salesperson of the partner if any """
        partner_rec = self.session.browse('res.partner', self.options.partner_id)
        if partner_rec.user_id:
            return {'user_id': partner_rec.user_id.id}
        return {'user_id': False}