<commit_before># ©  2008-2020 Deltatech
#              <NAME> <dhongu(@)gmail(.)com
# See README.rst file on addons root folder for license details


from odoo import api, fields, models


class ResPartner(models.Model):
    _inherit = "res.partner"

    mean_transp = fields.Char(string="Mean transport")


class AccountInvoice(models.Model):
    _inherit = "account.move"

    delegate_id = fields.Many2one(
        "res.partner",
        string="Delegate",
        readonly=True,
        states={"draft": [("readonly", False)]},
        domain=[("is_company", "=", False)],
    )

    mean_transp = fields.Char(
        string="Mean transport",
        readonly=True,
        states={"draft": [("readonly", False)]},
    )

    @api.model
    def default_get(self, fields_list):
        defaults = super(AccountInvoice, self).default_get(fields_list)
        if "delegate_id" not in defaults:
            if "default_delegate_id" in self.env.context:
                defaults["default_delegate_id"] = defaults["default_delegate_id"]
        return defaults

    @api.onchange("delegate_id")
    def on_change_delegate_id(self):
        if self.delegate_id:
            self.mean_transp = self.delegate_id.mean_transp

    # anularea facturilor cu zero

    def action_invoice_cancel(self):
        for invoice in self:
            if invoice.amount_total == 0.0 and invoice.state == "paid":
                invoice.state = "open"
                # invoice.write({'state':'open'})

        return super(AccountInvoice, self).action_invoice_cancel()

    def set_origin_with_picking(self):
        for invoice in self:
            pickings = self.env["stock.picking"]
            for line in invoice.invoice_line_ids:
                for sale_line in line.sale_line_ids:
                    for move in sale_line.move_ids:
                        if move.picking_id.state == "done":
                            pickings |= move.picking_id
                if line.purchase_line_id:
                    for move in line.purchase_line_id.move_ids:
                        if move.picking_id.state == "done":
                            pickings |= move.picking_id
            origin = ""
            for picking in pickings:
                origin += " " + picking.name

            if origin:
                invoice.write({"origin": origin})


#
# class account_invoice_line(models.Model):
#     _inherit = "account.move.line"
#
#     sequence = fields.Integer(default=1)
#
#     price_unit_without_taxes = fields.Float(string='Unit Price without taxes', store=True, readonly=True,
#                                             compute='_compute_price')
#
#     price_taxes = fields.Float(string='Taxes', digits='Account', store=True, readonly=True,
#                                compute='_compute_price')
#
#     price_normal_taxes = fields.Float(tring='Normal Taxes', digits='Account', store=True,
#                                       readonly=True, compute='_compute_price')
#
#     """
#     # campurile standard
#     price_unit = fields.Float(string='Unit Price', required=True, digits=dp.get_precision('Product Price'))
#     price_subtotal = fields.Monetary(string='Amount',<commit_msg>in 15 campul este invoice_origin nu origin<commit_after># ©  2008-2020 Deltatech
#              <NAME> <<EMAIL>(@)<EMAIL>(.)com
# See README.rst file on addons root folder for license details


from odoo import api, fields, models


class ResPartner(models.Model):
    _inherit = "res.partner"

    mean_transp = fields.Char(string="Mean transport")


class AccountInvoice(models.Model):
    _inherit = "account.move"

    delegate_id = fields.Many2one(
        "res.partner",
        string="Delegate",
        readonly=True,
        states={"draft": [("readonly", False)]},
        domain=[("is_company", "=", False)],
    )

    mean_transp = fields.Char(
        string="Mean transport",
        readonly=True,
        states={"draft": [("readonly", False)]},
    )

    @api.model
    def default_get(self, fields_list):
        defaults = super(AccountInvoice, self).default_get(fields_list)
        if "delegate_id" not in defaults:
            if "default_delegate_id" in self.env.context:
                defaults["default_delegate_id"] = defaults["default_delegate_id"]
        return defaults

    @api.onchange("delegate_id")
    def on_change_delegate_id(self):
        if self.delegate_id:
            self.mean_transp = self.delegate_id.mean_transp

    # anularea facturilor cu zero

    def action_invoice_cancel(self):
        for invoice in self:
            if invoice.amount_total == 0.0 and invoice.state == "paid":
                invoice.state = "open"
                # invoice.write({'state':'open'})

        return super(AccountInvoice, self).action_invoice_cancel()

    def set_origin_with_picking(self):
        for invoice in self:
            pickings = self.env["stock.picking"]
            for line in invoice.invoice_line_ids:
                for sale_line in line.sale_line_ids:
                    for move in sale_line.move_ids:
                        if move.picking_id.state == "done":
                            pickings |= move.picking_id
                if line.purchase_line_id:
                    for move in line.purchase_line_id.move_ids:
                        if move.picking_id.state == "done":
                            pickings |= move.picking_id
            origin = ""
            for picking in pickings:
                origin += " " + picking.name

            if origin:
                invoice.write({"invoice_origin": origin})


#
# class account_invoice_line(models.Model):
#     _inherit = "account.move.line"
#
#     sequence = fields.Integer(default=1)
#
#     price_unit_without_taxes = fields.Float(string='Unit Price without taxes', store=True, readonly=True,
#                                             compute='_compute_price')
#
#     price_taxes = fields.Float(string='Taxes', digits='Account', store=True, readonly=True,
#                                compute='_compute_price')
#
#     price_normal_taxes = fields.Float(tring='Normal Taxes', digits='Account', store=True,
#                                       readonly=True, compute='_compute_price')
#
#     """
#     # campurile standard
#     price_unit = fields.Float(string='Unit Price', required=True, digits=dp.get_precision('Product Price'))
#     price_subtotal = fields.Monetary(string='Amount',
{'fraction_non_alphanumeric': 0.11335403726708075, 'fraction_numerical': 0.004037267080745342, 'mean_word_length': 2.2060726729716276, 'pattern_counts': {'":': 12, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5556211', 'n_tokens_mistral': 1916, 'n_tokens_neox': 1809, 'n_words': 373}