def _get_action(self, holds):
     action = super()._get_action(holds)
     if self.return_action == "sub":
         sub_contract = self.env["recurring.contract"].browse(
             self.env.context.get("contract_id")
         )
         # Prevent choosing child completing in less than 2 years
         in_two_years = date.today() + relativedelta(years=2)
         child = holds[0].child_id
         if child.completion_date and child.completion_date < in_two_years:
             raise UserError(
                 _(
                     "Completion date of child is in less than 2 years! "
                     "Please choose another child."
                 )
             )
         sub_contract.write({"child_id": child.id})
         sub_contract.next_invoice_date = self.env.context.get("next_invoice_date")
         action.update(
             {
                 "res_model": "recurring.contract",
                 "res_id": sub_contract.id,
                 "view_mode": "form",
             }
         )
         action["context"] = self.with_context({"default_type": "S", }).env.context
     return action
 def _get_action(self, holds):
     action = super(ChildHoldWizard, self)._get_action(holds)
     if self.return_action == 'sub':
         sub_contract = self.env['recurring.contract'].browse(
             self.env.context.get('contract_id')).with_context(
                 allow_rewind=True)
         # Prevent choosing child completing in less than 2 years
         in_two_years = datetime.today() + relativedelta(years=2)
         child = holds[0].child_id
         if child.completion_date and fields.Datetime.from_string(
                 child.completion_date) < in_two_years:
             raise UserError(
                 _("Completion date of child is in less than 2 years! "
                   "Please choose another child."))
         sub_contract.write({'child_id': child.id})
         sub_contract.next_invoice_date = self.env.context.get(
             'next_invoice_date')
         action.update({
             'res_model': 'recurring.contract',
             'res_id': sub_contract.id,
             'view_mode': 'form',
         })
         action['context'] = self.with_context({
             'default_type': 'S',
         }).env.context
     return action
 def _get_action(self, holds):
     action = super(ChildHoldWizard, self)._get_action(holds)
     if self.return_action == 'sub':
         sub_contract = self.env['recurring.contract'].browse(
             self.env.context.get('contract_id')).with_context(
             allow_rewind=True)
         # Prevent choosing child completing in less than 2 years
         in_two_years = datetime.today() + relativedelta(years=2)
         child = holds[0].child_id
         if child.completion_date and fields.Datetime.from_string(
                 child.completion_date) < in_two_years:
             raise UserError(_(
                 "Completion date of child is in less than 2 years! "
                 "Please choose another child."
             ))
         sub_contract.write({'child_id': child.id})
         sub_contract.next_invoice_date = self.env.context.get(
             'next_invoice_date')
         action.update({
             'res_model': 'recurring.contract',
             'res_id': sub_contract.id,
             'view_mode': 'form',
         })
         action['context'] = self.with_context({
             'default_type': 'S',
         }).env.context
     return action
 def _compute_dates(self, date_start=None, date_stop=None):
     if not date_start or not date_stop:
         # Select the last year period
         year = datetime.today()
         year = year - relativedelta(years=1)
         fy = self.env.user.company_id.compute_fiscalyear_dates(year)
         date_start = fields.Date.to_string(fy['date_from'])
         date_stop = fields.Date.to_string(fy['date_to'])
     return date_start, date_stop
 def _compute_dates(self, date_start=None, date_stop=None):
     if not date_start or not date_stop:
         # Select the last year period
         year = datetime.today()
         year = year - relativedelta(years=1)
         fy = self.env.user.company_id.compute_fiscalyear_dates(year)
         date_start = fields.Date.to_string(fy['date_from'])
         date_stop = fields.Date.to_string(fy['date_to'])
     return date_start, date_stop
    def add_to_wordpress(self, company_id=None):
        in_two_years = date.today() + relativedelta(years=2)
        valid_children = self.filtered(
            lambda c: c.state == "N" and c.desc_de and c.desc_fr and c.desc_it
            and c.project_id.description_fr and c.project_id.description_de and
            c.project_id.description_it and c.fullshot and
            (not c.completion_date or c.completion_date > in_two_years))

        error = self - valid_children
        if error:
            number = str(len(error))
            logger.error(
                f"{number} children have invalid data and were not pushed to wordpress"
            )

        wp_config = self.env["wordpress.configuration"].get_config(company_id)
        wp = WPSync(wp_config)
        return wp.upload_children(valid_children)
    def add_to_wordpress(self):
        # Solve the encoding problems on child's descriptions
        reload(sys)
        sys.setdefaultencoding('UTF8')

        in_two_years = datetime.today() + relativedelta(years=2)
        valid_children = self.filtered(
            lambda c: c.state == 'N' and c.desc_de and c.desc_fr and c.desc_it
            and c.project_id.description_fr and c.project_id.description_de and
            c.project_id.description_it and c.fullshot and
            (not c.completion_date or fields.Datetime.from_string(
                c.completion_date) > in_two_years))

        error = self - valid_children
        if error:
            logger.error(
                "%s children have invalid data and were not pushed to "
                "wordpress." % str(len(error)))

        wp = WPSync()
        return wp.upload_children(valid_children)
 def print_report(self):
     """
     Print selected child dossier
     :return: Generated report
     """
     model = 'compassion.child'
     # Prevent printing dossier if completion date is in less than 2 years
     in_two_years = datetime.today() + relativedelta(years=2)
     records = self.env[model].browse(self.env.context.get(
         'active_ids')).filtered(
         lambda c: c.state in ('N', 'I', 'P') and c.desc_en and
         (not c.completion_date or fields.Datetime.from_string(
             c.completion_date) > in_two_years)
     ).with_context(lang=self.lang)
     data = {
         'lang': self.lang,
         'doc_ids': records.ids,
         'is_pdf': self.pdf,
         'type': self.type
     }
     report_obj = self.env['report'].with_context(lang=self.lang)
     if self.pdf:
         name = records.local_id if len(records) == 1 else 'dossiers'
         self.pdf_name = name + '.pdf'
         self.pdf_download = base64.b64encode(
             report_obj.with_context(
                 must_skip_send_to_printer=True).get_pdf(
                     records.ids, self.type, data=data))
         self.state = 'pdf'
         return {
             'name': 'Download report',
             'type': 'ir.actions.act_window',
             'res_model': self._name,
             'res_id': self.id,
             'view_mode': 'form',
             'target': 'new',
             'context': self.env.context,
         }
     return report_obj.get_action(records.ids, self.type, data=data)
    def add_to_wordpress(self):
        # Solve the encoding problems on child's descriptions
        reload(sys)
        sys.setdefaultencoding('UTF8')

        in_two_years = datetime.today() + relativedelta(years=2)
        valid_children = self.filtered(
            lambda c: c.state == 'N' and c.desc_de and
            c.desc_fr and c.desc_it and
            c.project_id.description_fr and c.project_id.description_de and
            c.project_id.description_it and c.fullshot and
            (not c.completion_date or
             fields.Datetime.from_string(c.completion_date) > in_two_years)
        )

        error = self - valid_children
        if error:
            logger.error(
                "%s children have invalid data and were not pushed to "
                "wordpress." % str(len(error))
            )

        wp = WPSync()
        return wp.upload_children(valid_children)
Exemple #10
0
    def compute_payment_due_ids(self):
        date_ref = self.date_invoice or fields.Date.today()
        amount = self.amount_total
        sign = 1 < 0 and -1 or 1
        due_ids = [(5,)]
        result = []
        if self.env.context.get('currency_id'):
            currency = self.env['res.currency'].browse(self.env.context['currency_id'])
        else:
            currency = self.env.user.company_id.currency_id
        for line in self.payment_term_id.line_ids:
            if line.value == 'fixed':
                amt = sign * currency.round(line.value_amount)
            elif line.value == 'percent':
                amt = currency.round(self.amount_total * (line.value_amount / 100.0))
            elif line.value == 'balance':
                amt = currency.round(amount)
            if amt:
                next_date = fields.Date.from_string(date_ref)
                if line.option == 'day_after_invoice_date':
                    next_date += relativedelta(days=line.days)
                    if line.day_of_the_month > 0:
                        months_delta = (line.day_of_the_month < next_date.day) and 1 or 0
                        next_date += relativedelta(day=line.day_of_the_month, months=months_delta)
                elif line.option == 'after_invoice_month':
                    next_first_date = next_date + relativedelta(day=1, months=1)  # Getting 1st of next month
                    next_date = next_first_date + relativedelta(days=line.days - 1)
                elif line.option == 'day_following_month':
                    next_date += relativedelta(day=line.days, months=1)
                elif line.option == 'day_current_month':
                    next_date += relativedelta(day=line.days, months=0)
                result.append((fields.Date.to_string(next_date), amt))

                # Aggiungo la riga all'array
                due_ids.append((0, 0, {
                    'amount': amt,
                    'date': next_date,
                    'fatturapa_payment_method_id': line.fatturapa_payment_method_id.id
                }))
                amount -= amt


        self.payment_due_ids = due_ids
Exemple #11
0
    def perform_distribution(self, date_start=None, date_stop=None):
        """
        Perform the attribution of the analytic lines.
        The attribution is done for each general account.
        By default it takes the last fiscal year for the computation.
        """
        if not date_start or not date_stop:
            # Select the last year period
            year = datetime.today()
            year = year - relativedelta(years=1)
            fy = self.env.user.company_id.compute_fiscalyear_dates(year)
            date_start = fields.Date.to_string(fy['date_from'])
            date_stop = fields.Date.to_string(fy['date_to'])

        analytic_line_obj = self.env['account.analytic.line']
        tag_id = self.env.ref(
            'account_analytic_attribution.tag_attribution').id

        # Remove old attributions for avoiding duplicates
        old_lines = analytic_line_obj.search([('tag_ids', '=', tag_id),
                                              ('date', '>=', date_start),
                                              ('date', '<=', date_stop)])
        old_lines.unlink()

        # Perform the attribution for each analytic line
        analytic_lines = analytic_line_obj.search([
            ('date', '>=', date_start),
            ('date', '<=', date_stop),
        ])
        generated_lines = analytic_line_obj

        # Get the total amount to attribute for each analytic account
        #   ->   {analytic_id: {general_account_id: total}}
        attribution_amounts = dict()
        for line in analytic_lines:
            analytic_id = line.account_id.id
            account_id = line.general_account_id.id
            analytic_attribution = attribution_amounts.get(
                analytic_id, {account_id: 0.0})
            total = analytic_attribution.get(account_id, 0.0) + line.amount
            analytic_attribution[account_id] = total
            attribution_amounts[analytic_id] = analytic_attribution

        # Attribute the amounts
        analytic_obj = self.env['account.analytic.account']
        account_obj = self.env['account.account']
        for analytic_id, attribution in attribution_amounts.iteritems():
            for account_id, amount_total in attribution.iteritems():
                account = account_obj.browse(account_id)
                account_tag_ids = account.tag_ids.ids
                analytic = analytic_obj.browse(analytic_id)
                analytic_tag_ids = analytic.tag_ids.ids
                attribution_rule = self.get_attribution(
                    account_tag_ids, analytic_tag_ids, date_stop)
                if attribution_rule:
                    prefix = (analytic.code and analytic.code + '-') or ''
                    for rule in attribution_rule.account_distribution_line_ids:
                        line = analytic_line_obj.create({
                            'name':
                            'Analytic attribution for ' + analytic.name,
                            'account_id':
                            rule.account_analytic_id.id,
                            'date':
                            date_stop,
                            'tag_ids': [(6, 0, [tag_id])],
                            'amount':
                            amount_total * (rule.rate / 100),
                            'general_account_id':
                            account_id,
                            'ref':
                            prefix + analytic.name,
                        })
                        generated_lines += line

        return generated_lines
Exemple #12
0
 def next_fiscal_year(self):
     today = datetime.today()
     fy = self.env.user.company_id.compute_fiscalyear_dates(today)
     next_fy = fy['date_to'] + relativedelta(days=1)
     next_fy.hour = 20
     return fields.Datetime.to_string(next_fy)