<commit_before># -*- coding: utf-8 -*-
###############################################################################
#                                                                             #
# Copyright (C) 2016  <NAME> - KMEE                                #
#                                                                             #
# This program is free software: you can redistribute it and/or modify        #
# it under the terms of the GNU Affero General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or           #
# (at your option) any later version.                                         #
#                                                                             #
# This program is distributed in the hope that it will be useful,             #
# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
# GNU Affero General Public License for more details.                         #
#                                                                             #
# You should have received a copy of the GNU Affero General Public License    #
# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
###############################################################################

from openerp import models, api


class ProcurementOrder(models.Model):
    _inherit = "procurement.order"

    @api.model
    def _run_move_create(self, procurement):
        result = super(ProcurementOrder, self)._run_move_create(procurement)
        if procurement.rule_id and procurement.rule_id.fiscal_category_id:
            result.update({
                'fiscal_category_id':
                    procurement.rule_id.fiscal_category_id.id,
            })

            if not procurement.move_dest_id:
                return result

            ctx = dict(self.env.context)
            ctx.update({'use_domain': ('use_picking', '=', True)})
            move = procurement.move_dest_id
            rule = procurement.rule_id
            kwargs = {
                'partner_id': move.partner_id.id,
                'product_id': procurement.product_id.id,
                'partner_invoice_id':  move.partner_id.id,
                # TODO: Implement fuction to compute partner invoice id
                'partner_shipping_id': move.partner_id.id,
                'fiscal_category_id': rule.fiscal_category_id.id,
                'company_id': procurement.company_id.id,
                'context': ctx,
            }

            partner = move.picking_id.partner_id
            obj_fp_rule = self.env['account.fiscal.position.rule']
            product_fc_id = obj_fp_rule.with_context(
                ctx).product_fiscal_category_map(
                    kwargs.get('product_id'),
                    kwargs.get('fiscal_category_id'),
                    partner.state_id.id)

            if product_fc_id:
                kwargs['fiscal_category_id'] = product_fc_id
                result['fiscal_category_id'] = product_fc_id
            else:
                result['fiscal_category_id'] = kwargs.get(
                    'fiscal_category_id')

            result_fr = obj_fp_rule.with_context(ctx).apply_fiscal_mapping(
                {'value': {}}, **kwargs)

            result.update({
                'fiscal_position': result_fr['value']['fiscal_position']})
        return result<commit_msg>[FIX] Fix procurement rule company_id<commit_after># -*- coding: utf-8 -*-
###############################################################################
#                                                                             #
# Copyright (C) 2016  <NAME> - KMEE                                #
#                                                                             #
# This program is free software: you can redistribute it and/or modify        #
# it under the terms of the GNU Affero General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or           #
# (at your option) any later version.                                         #
#                                                                             #
# This program is distributed in the hope that it will be useful,             #
# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
# GNU Affero General Public License for more details.                         #
#                                                                             #
# You should have received a copy of the GNU Affero General Public License    #
# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
###############################################################################

from openerp import models, api


class ProcurementOrder(models.Model):
    _inherit = "procurement.order"

    @api.model
    def _run_move_create(self, procurement):
        result = super(ProcurementOrder, self)._run_move_create(procurement)
        if (procurement.rule_id and procurement.rule_id.fiscal_category_id and
            procurement.move_dest_id):
            ctx = dict(self.env.context)
            ctx.update({'use_domain': ('use_picking', '=', True)})
            partner = (
                procurement.rule_id.partner_address_id or (
                    procurement.group_id and procurement.group_id.partner_id)
            )
            company = (procurement.warehouse_id.company_id or
                       procurement.company_id)
            kwargs = {
                'partner_id': partner.id,
                'product_id': procurement.product_id.id,
                'partner_invoice_id':  partner.id,
                # TODO: Implement fuction to compute partner invoice id
                'partner_shipping_id': partner.id,
                'fiscal_category_id': (
                    procurement.rule_id.fiscal_category_id.id
                ),
                'company_id': company.id,
                'context': ctx,
            }

            obj_fp_rule = self.env['account.fiscal.position.rule']
            product_fc_id = obj_fp_rule.with_context(
                ctx).product_fiscal_category_map(
                    kwargs.get('product_id'),
                    kwargs.get('fiscal_category_id'),
                    partner.state_id.id)

            if product_fc_id:
                kwargs['fiscal_category_id'] = product_fc_id
                result['fiscal_category_id'] = product_fc_id
            else:
                result['fiscal_category_id'] = kwargs.get(
                    'fiscal_category_id')

            result_fr = obj_fp_rule.with_context(ctx).apply_fiscal_mapping(
                {'value': {}}, **kwargs)

            result.update({
                'fiscal_position': result_fr['value']['fiscal_position']})
        return result
{'fraction_non_alphanumeric': 0.12163125623841438, 'fraction_numerical': 0.0017111079423926994, 'mean_word_length': 1.528478731074261, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2547693', 'n_tokens_mistral': 1764, 'n_tokens_neox': 1655, 'n_words': 399}