콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
9170 화면

The goal is, in a multi-company instance, to enable duplication of sale orders emitted by other companies. So far other the instance configuration enable companies to see each other sale orders without modify them, which is good. Now when it comes to duplication, a write permission error rises. It looks like the problem is the shop_id field, which can't be set to an other company shop, which is fine as you would indeed expect the shop of the company attached to the current user to be used instead. So overriding the copy method of the sale_order class would probably be enough.

The only remaining problem is, how do you get the needed shop_id?

Here is what I have tried so far :

class sale_order(osv.Model):

    _inherit = 'sale.order'

    def _get_shop_id(self, cr, uid, id, default=None, context=None):
    print 'uid', uid
    user = self.pool.get('res.users').browse(cr, uid, uid,
                               context=context)
    company_id = user.company_id.id
    shop = self.pool.get('sale.shop').browse(cr, uid, company_id,
                               context=context)

    print 'company_id', company_id
    print 'shop_id', shop.id # return the same result as company_id :(
    return shop.id

    def copy(self, cr, uid, id, default=None, context=None):
    print '========== overloaded copy sale_order'
    shop_id = self._get_shop_id(cr, uid, id, default, context)

    if not default:
        default = {}
    default.update({
        'date_order': fields.date.context_today(self, cr, uid, context=context),
        'state': 'draft',
        'invoice_ids': [],
        'date_confirm': False,
        'client_order_ref': '',
        'name': self.pool.get('ir.sequence').get(cr, uid, 'sale.order'),
        'shop_id': shop_id,
    })
    return super(sale_order, self).copy(cr, uid, id, default, context=context)
아바타
취소
작성자 베스트 답변

Here is a solution :

def _get_shop_id(self, cr, uid, id, default=None, context=None):
    user = self.pool.get('res.users').browse(cr, uid, uid,
                        context=context)
    company_id = user.company_id.id
    company_name = user.company_id.name
    shop_ids = self.pool.get('sale.shop').search(
    cr, uid, [ ('company_id','=', company_id) ], context=context)

    if shop_ids:
    return shop_ids[0]

    raise osv.except_osv(
    _("Error"),
    _('No shop defined for the company "%s"'% company_name)
    )
아바타
취소
관련 게시물 답글 화면 활동
2
11월 17
5750
1
5월 25
2501
0
6월 20
5739
2
6월 17
19292
2
2월 17
3679