0

Odoo 13中,我们遇到了多公司问题,每个公司需要有相同的工资规则和工资结构(属于 OCA 工资模块)。

我们不想静态定义每个公司的记录:

我们想要创建的是一个Odoo函数,它可以自动为每个公司创建记录,并链接到适当公司的会计计划中的适当帐户:

@api.model
def create_rule_for_every_company(self):
    """
    function that'll create the rule for each company, in the group_system
    """
    

(从 XML 数据文件安装模块时调用函数)

但很快意识到你需要对工资结构等做同样的事情,所以我想知道在我不知道的 Odoo 逻辑中是否有更简单的方法来做到这一点

这样做的目的是让每条规则都与正确的:account.account公司相关联。

4

1 回答 1

0

基本上,我想出了这个:

  @api.model
        def create_rule_for_every_company(self):
            """
            function that'll create the rule for each company, in the group_system
            """
            list_companies = self.env['res.company'].sudo().search([])
            list_rules = self.env['hr.salary.rule'].sudo().search([('company_id', '=', 0)])
            for rule in list_rules:
              if rule.company_id is False:
                for company in list_companies:
                    if rule.child_ids:
                        for child in rule.child_ids:
                            child_copy = child.copy()
                            child_copy.sudo().write({'company_id': company.id, 'parent_rule_id': rule.id, 'rubric_id': child.rubric_id})
                        rule_copy = rule.sudo().copy()
                        rule_copy.sudo().write({'company_id': company.id, 'rubric_id': rule.rubric_id})
                    else:
                        rule_copy = rule.sudo().copy()
                        rule_copy.sudo().write({'company_id': company.id, 'rubric_id': rule.rubric_id})
              for rule in list_rules:
                  if rule.company_id is False:
                     self.sudo().unlink(rule.id)

仍在寻找更优化的解决方案。

这个解决方案感觉不稳定。

于 2021-11-20T10:06:46.303 回答