<commit_before># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    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/>.
#
##############################################################################
import time
from lxml import etree

from osv import osv, fields

class payment_order_create(osv.osv_memory):
    """
    Create a payment object with lines corresponding to the account move line
    to pay according to the date and the mode provided by the user.
    Hypothesis:
    - Small number of non-reconcilied move line , payment mode and bank account type,
    - Big number of partner and bank account.

    If a type is given, unsuitable account Entry lines are ignored.
    """

    _name = 'payment.order.create'
    _description = 'payment.order.create'
    _columns = {
        'duedate': fields.date('Due Date', required=True),
        'entries': fields.many2many('account.move.line', 'line_pay_rel', 'pay_id', 'line_id', 'Entries')
                }
    _defaults = {
         'duedate': time.strftime('%Y-%m-%d'),
                 }

    def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
        res = super(payment_order_create, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=False)
        if context and 'line_ids' in context:
            view_obj = etree.XML(res['arch'])
            child = view_obj.getchildren()[0]
            domain = '[("id", "in", '+ str(context['line_ids'])+')]'
            field = etree.Element('field', attrib={'domain': domain, 'name':'entries', 'colspan':'4', 'height':'300', 'width':'800', 'nolabel':"1"})
            child.addprevious(field)
            res['arch'] = etree.tostring(view_obj)
        return res

    def create_payment(self, cr, uid, ids, context=None):
        order_obj = self.pool.get('payment.order')
        line_obj = self.pool.get('account.move.line')

        data = self.read(cr, uid, ids, [], context)[0]
        line_ids= data['entries']
        if not line_ids: return {}

        payment = order_obj.browse(cr, uid, data['active_id'],
                context=context)
        t = payment.mode and payment.mode.type.id or None
        line2bank = pool.get('account.move.line').line2bank(cr, uid,
                line_ids, t, context)

        ## Finally populate the current payment with new lines:
        for line in line_obj.browse(cr, uid, line_ids, context=context):
            if payment.date_prefered == "now":
                #no payment date => immediate payment
                date_to_pay = False
            elif payment.date_prefered == 'due':
                date_to_pay = line.date_maturity
            elif payment.date_prefered == 'fixed':
                date_to_pay = payment.date_planned
            pool.get('payment.line').create(cr, uid,{
                'move_line_id': line.id,
                'amount_currency': line.amount_to_pay,
                'bank_id': line2bank.get(line.id),
                'order_id': payment.id,
                'partner_id': line.partner_id and line.partner_id.id or False,
                'communication': line.ref or '/',
                'date': date_to_pay,
                'currency': line.invoice and line.invoice.currency_id.id or False,
                }, context=context)
        return {}

    def search_entries(self, cr, uid, ids, context=None):
        order_obj = self.pool.get('payment.order')
        line_obj = self.pool.get('account.move.line')
        mod_obj = self.pool.get('ir.model.data')

        data = self.read(cr, uid, ids, [], context=context)[0]
        search_due_date = data['duedate']
        payment = order_obj.browse(cr, uid, context['active_id'], context=context)
        ctx = ''
        if payment.mode:
            ctx = '''context="{'journal_id': %d}"''' % payment.mode.journal.id

        # Search for move line to pay:
        domain = [('reconcile_id', '=', False),('account_id.type', '=', 'payable'),('amount_to_pay', '>', 0)]
        domain = domain + ['|',('date_maturity','<',search_due_date),('date_maturity','=',False)]
        line_ids = line_obj.search(cr, uid, domain, context=context)
        context.update({'line_ids': line_ids})
        model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_create_payment_order_lines')], context=context)<commit_msg>[FIX] (5.0 - 6.0)Account_payment : Import of move line should include the date of search due date<commit_after># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    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/>.
#
##############################################################################
import time
from lxml import etree

from osv import osv, fields

class payment_order_create(osv.osv_memory):
    """
    Create a payment object with lines corresponding to the account move line
    to pay according to the date and the mode provided by the user.
    Hypothesis:
    - Small number of non-reconcilied move line , payment mode and bank account type,
    - Big number of partner and bank account.

    If a type is given, unsuitable account Entry lines are ignored.
    """

    _name = 'payment.order.create'
    _description = 'payment.order.create'
    _columns = {
        'duedate': fields.date('Due Date', required=True),
        'entries': fields.many2many('account.move.line', 'line_pay_rel', 'pay_id', 'line_id', 'Entries')
                }
    _defaults = {
         'duedate': time.strftime('%Y-%m-%d'),
                 }

    def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
        res = super(payment_order_create, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=False)
        if context and 'line_ids' in context:
            view_obj = etree.XML(res['arch'])
            child = view_obj.getchildren()[0]
            domain = '[("id", "in", '+ str(context['line_ids'])+')]'
            field = etree.Element('field', attrib={'domain': domain, 'name':'entries', 'colspan':'4', 'height':'300', 'width':'800', 'nolabel':"1"})
            child.addprevious(field)
            res['arch'] = etree.tostring(view_obj)
        return res

    def create_payment(self, cr, uid, ids, context=None):
        order_obj = self.pool.get('payment.order')
        line_obj = self.pool.get('account.move.line')

        data = self.read(cr, uid, ids, [], context)[0]
        line_ids= data['entries']
        if not line_ids: return {}

        payment = order_obj.browse(cr, uid, data['active_id'],
                context=context)
        t = payment.mode and payment.mode.type.id or None
        line2bank = pool.get('account.move.line').line2bank(cr, uid,
                line_ids, t, context)

        ## Finally populate the current payment with new lines:
        for line in line_obj.browse(cr, uid, line_ids, context=context):
            if payment.date_prefered == "now":
                #no payment date => immediate payment
                date_to_pay = False
            elif payment.date_prefered == 'due':
                date_to_pay = line.date_maturity
            elif payment.date_prefered == 'fixed':
                date_to_pay = payment.date_planned
            pool.get('payment.line').create(cr, uid,{
                'move_line_id': line.id,
                'amount_currency': line.amount_to_pay,
                'bank_id': line2bank.get(line.id),
                'order_id': payment.id,
                'partner_id': line.partner_id and line.partner_id.id or False,
                'communication': line.ref or '/',
                'date': date_to_pay,
                'currency': line.invoice and line.invoice.currency_id.id or False,
                }, context=context)
        return {}

    def search_entries(self, cr, uid, ids, context=None):
        order_obj = self.pool.get('payment.order')
        line_obj = self.pool.get('account.move.line')
        mod_obj = self.pool.get('ir.model.data')

        data = self.read(cr, uid, ids, [], context=context)[0]
        search_due_date = data['duedate']
        payment = order_obj.browse(cr, uid, context['active_id'], context=context)
        ctx = ''
        if payment.mode:
            ctx = '''context="{'journal_id': %d}"''' % payment.mode.journal.id

        # Search for move line to pay:
        domain = [('reconcile_id', '=', False),('account_id.type', '=', 'payable'),('amount_to_pay', '>', 0)]
        domain = domain + ['|',('date_maturity','<=',search_due_date),('date_maturity','=',False)]
        line_ids = line_obj.search(cr, uid, domain, context=context)
        context.update({'line_ids': line_ids})
        model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_create_payment_order_lines')], context=context)
{'fraction_non_alphanumeric': 0.15732161620021015, 'fraction_numerical': 0.00534912599102111, 'mean_word_length': 2.8239590942293646, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '251586', 'n_tokens_mistral': 3169, 'n_tokens_neox': 3015, 'n_words': 827}