예제 #1
0
 def action_assign(self):
     reg_obj = self.env["academy.registration"]
     reg_ids = util.active_ids(self._context, reg_obj)
     regs = reg_obj.search([("id", "in", reg_ids),
                            ("state", "=", "registered")])
     if regs:
         regs.action_assign()
     return {'type': 'ir.actions.act_window_close'}
예제 #2
0
 def action_cancel(self, cr, uid, ids, context=None):
     invoice_ids = util.active_ids(context, "account.invoice")
     invoice_obj = self.pool["account.invoice"]
     for invoice in invoice_obj.browse(cr,
                                       uid,
                                       invoice_ids,
                                       context=context):
         invoice_obj._cancel_invoice_all(cr, uid, invoice, context=context)
     return {"type": "ir.actions.act_window_close"}
    def action_post_payment(self, cr, uid, ids, context=None):
        # get objects
        wizard = self.browse(cr, uid, ids[0], context=context)
        reg_inv_obj = self.pool["academy.registration.invoice"]
        invoice_obj = self.pool["account.invoice"]
        payment_obj = self.pool["academy.payment"]
        payment_ids = util.active_ids(context, payment_obj)

        # process payments
        for payment in payment_obj.browse(cr,
                                          uid,
                                          payment_ids,
                                          context=context):
            if payment.invoice_id:
                continue

            semester = payment.semester_id
            reg = payment.reg_id

            reg_inv_id = reg_inv_obj.search_id(
                cr, uid, [("registration_id", "=", reg.id),
                          ("semester_id", "=", semester.id)])
            if not reg_inv_id:
                continue

            # get invocie
            invoice = reg_inv_obj.browse(cr, uid, reg_inv_id,
                                         context=context).invoice_id
            if invoice.state not in (
                    "draft", "cancel"
            ) and invoice.residual and invoice.residual >= payment.amount:
                # do payment
                res = invoice_obj._create_payment(cr,
                                                  uid,
                                                  invoice.id,
                                                  wizard.journal_id.id,
                                                  amount=payment.amount,
                                                  date=payment.date,
                                                  post=True,
                                                  context=context)

                # check if everything ok, and add invoice
                # to payment
                voucher_id = res.get("voucher_id")
                if voucher_id:
                    payment_obj.write(cr,
                                      uid, [payment.id], {
                                          "invoice_id": invoice.id,
                                          "voucher_id": voucher_id
                                      },
                                      context=context)

        return {"type": "ir.actions.act_window_close"}
예제 #4
0
    def do_create(self, cr, uid, ids, context=None):
        holiday_obj = self.pool.get("official.holiday")
        template_obj = self.pool.get("official.holiday.template")
        user_obj = self.pool.get("res.users")

        template_ids = template_obj.search(cr,uid,[("id","in",util.active_ids(context))])
        company_id = user_obj.browse(cr, uid, uid, context).company_id.id
        official_holiday_ids = []

        for template_id in template_ids:
            template = template_obj.browse(cr, uid, template_id)
            for holiday in template.official_holiday_ids:
                official_holiday_ids.append(holiday.id)

        for wizard in self.browse(cr, uid, ids, context=context):
            if wizard.calendar_ids:
                for calendar in wizard.calendar_ids:
                    holiday_obj.create_calendar_entries(cr, uid, official_holiday_ids, fiscalyear_id=wizard.fiscalyear_id.id, company_id=company_id, calendar_id=calendar.id,context=context)
            else:
                holiday_obj.create_calendar_entries(cr, uid, official_holiday_ids, fiscalyear_id=wizard.fiscalyear_id.id, company_id=company_id, context=context)

        return { "type" : "ir.actions.act_window_close" }
    def action_create(self, cr, uid, ids, context=None):
        wizard = self.browse(cr, uid, ids[0], context)

        report_ctx = context and dict(context) or {}
        report_ctx["date_start"] = wizard.date_start
        report_ctx["date_end"] = wizard.date_end

        if wizard.unit == "semester":
            if wizard.sem_start_id.id == wizard.sem_end_id.id:
                report_ctx["duration_title"] = wizard.sem_start_id.name_get(
                )[0][1]
            else:
                report_ctx["duration_title"] = "%s - %s" % (
                    wizard.sem_start_id.name_get()[0][1],
                    wizard.sem_end_id.name_get()[0][1])
        elif wizard.unit == "period":
            if wizard.period_start_id.id == wizard.period_end_id.id:
                report_ctx["duration_title"] = wizard.period_start_id.name_get(
                )[0][1]
            else:
                report_ctx["duration_title"] = "%s - %s" % (
                    wizard.period_start_id.name_get()[0][1],
                    wizard.period_end_id.name_get()[0][1])
        else:
            f = format.LangFormat(cr, uid, context)
            report_ctx["duration_title"] = "%s - %s" % (f.formatLang(
                wizard.date_start,
                date=True), f.formatLang(wizard.date_end, date=True))

        datas = {
            "ids": util.active_ids(context, "academy.trainer"),
            "model": "academy.trainer"
        }
        return {
            "type": "ir.actions.report.xml",
            "report_name": "trainer.reg",
            "datas": datas,
            "context": report_ctx
        }
예제 #6
0
    def default_get(self, fields_list):
        res = super(wizard_export_bmd, self).default_get(fields_list)
        order_obj = self.env["pos.order"]
        orders = []
        
        session_ids = util.active_ids(self._context, "pos.session")
        if session_ids:
            orders = order_obj.search([("session_id","in",session_ids)], order="date_order asc")
        else:
            order_ids = util.active_ids(self._context, "pos.order")
            if order_ids:
                orders = order_obj.search([("id","in",order_ids)], order="date_order asc")
                
        lines = []
        
        # formats

        def formatFloat(inValue):
            return ("%.2f" % inValue).replace(".",",")
        
        def formatSymbol(value):
            if value:
                value = value.replace("/","")
                return value
            return None
        
        #internal_account_id
        for order in orders:      
            # config            
            cash_statement = order.session_id.cash_statement_id
            if not cash_statement:
                raise Warning(_("No cash statement for order %s found") % order.name)
            
            config = order.session_id.config_id
            currency = order.pricelist_id.currency_id
            belegkreis = formatSymbol(config.fpos_prefix or config.sequence_number.prefix)
            belegnr = order.name.split(config.fpos_prefix)[-1]
            belegdat = helper.strToLocalTimeFormat(self._cr, self._uid, order.date_order,"%d%m%Y", context=self._context)
            journal = cash_statement.journal_id
            debit_account = journal.default_debit_account_id
            credit_account = journal.default_credit_account_id
            internal_account = journal.internal_account_id
            if not internal_account:
                raise Warning(_("No internal account defined on Journal %s for cash transfers") % journal.name)
             
            name = []
            if order.pos_reference:
                name.append(order.pos_reference)
            if order.partner_id:
                name.append(order.partner_id.name)          
            name = " ".join(name)
             
            bookings = OrderedDict()
            def post(konto, betrag, betrag_gegenbuchung, mwst, steuer, text):
                # change sign
                key = (konto, mwst, text)
                booking = bookings.get(key)
                if booking is None:
                    booking = (betrag, steuer, betrag_gegenbuchung)
                else:
                    booking = (booking[0] + betrag, booking[1] + steuer, booking[2] + betrag_gegenbuchung)
                bookings[key] = booking
            
            # post sale            
            for line in order.lines:
                product = line.product_id
                
                # get tax
                tax = 0
                taxes = [t for t in product.taxes_id if not t.company_id or t.company_id == order.company_id]
                if taxes:
                    tax = int(taxes[0].amount * 100)
                
                tax_amount =  line.price_subtotal_incl - line.price_subtotal
                if product.income_pdt or product.expense_pdt:
                    account = internal_account
                    partner = order.partner_id
                    if partner:
                        if product.income_pdt:
                            account = partner.property_account_receivable
                        else:
                            account = partner.property_account_payable
                    post(account.code, line.price_subtotal, line.price_subtotal_incl, tax, tax_amount, name)
                else:
                    income_account = product.property_account_income
                    if not income_account:
                        income_account = product.categ_id.property_account_income_categ
                    if not income_account:
                        raise Warning(_("No income account for product %s defined") % product.name)
                    account = income_account
                    if not line.price_subtotal:
                        account = internal_account
                    post(account.code, line.price_subtotal, line.price_subtotal_incl, tax, tax_amount, name)
        
            # post payment
            for payment in order.statement_ids:                
                if payment.statement_id.id != cash_statement.id:
                    post(internal_account.code, -payment.amount, -payment.amount, 0, 0, payment.statement_id.journal_id.name)
                    
            # write bookings            
            for (konto, mwst, text), (betrag, steuer, betrag_gegenbuchung) in bookings.iteritems():
                sollbetrag = ""
                habenbetrag = ""
                sollbetrag_gegenbuchung = ""
                habenbetrag_gegenbuchung = ""
                gegenkonto = None
                
                if betrag < 0:
                    gegenkonto = credit_account.code
                    sollbetrag = formatFloat(abs(betrag))
                    habenbetrag_gegenbuchung = formatFloat(abs(betrag_gegenbuchung))
                else:
                    gegenkonto = debit_account.code
                    habenbetrag = formatFloat(abs(betrag))
                    sollbetrag_gegenbuchung = formatFloat(abs(betrag_gegenbuchung))
                    
                opnummer = ""
                valuta_datum = ""
                waehrung = currency.name
                fremdwaehrung = ""
                fremdwaehrung_sollbetrag = ""
                fremdwaehrung_habenbetrag = ""
                kostenstelle = ""
                ust_land = "1"
                ust_prozentsatz = ""
                ust_code = ""
                ust_sondercode = "0"
                buchungsart = "1"
                steuerbetrag = formatFloat(steuer)
                if mwst:
                    ust_prozentsatz = str(mwst)
                    ust_code = "2"
                    
                abweichende_zahlungsfrist = ""
                abweichende_kontofrist = ""
                abw_skontoprozentsatz = ""
                buchungstext = order.name
                buchungstext2 = text
                uid_nummer = ""
                dienstleistungsnummer = ""
                dienstleistungsland = ""
                dienstleistungsexport = ""
                dms_schluessel = ""
                kostentraeger = ""
                fremdbelegnummer = ""
                wert1 = ""
                wert2  = ""
                mahnsperre = ""
                kundendatenfeld = ""
                
                # buchung
                line = ";".join([konto,             #1 
                                 gegenkonto,        #2
                                 opnummer,          #3
                                 belegdat,          #4 
                                 valuta_datum,      #5
                                 waehrung,          #6
                                 sollbetrag,        #7
                                 habenbetrag,       #8
                                 steuerbetrag,      #9
                                 fremdwaehrung,     #10
                                 fremdwaehrung_sollbetrag,  #11
                                 fremdwaehrung_habenbetrag, #12
                                 kostenstelle,      #13
                                 belegkreis,        #14
                                 belegnr,           #15
                                 ust_land,          #16
                                 ust_prozentsatz,   #17
                                 ust_code,           #18
                                 ust_sondercode,     #19
                                 buchungsart,        #20
                                 abweichende_zahlungsfrist, #21
                                 abweichende_kontofrist, #22
                                 abw_skontoprozentsatz, #23
                                 buchungstext, #24
                                 buchungstext2, #25
                                 uid_nummer, #26
                                 dienstleistungsnummer, #27
                                 dienstleistungsland, #28
                                 dienstleistungsexport, #29
                                 dms_schluessel, #30
                                 kostentraeger, #31
                                 fremdbelegnummer, #32
                                 wert1, #33
                                 wert2, #34
                                 mahnsperre, #35
                                 kundendatenfeld #36
                                ]) + ";"
                                                                 
                lines.append(line)
                
                # gegen buchung
                line = ";".join([gegenkonto,        #1 
                                 konto,             #2
                                 opnummer,          #3
                                 belegdat,          #4 
                                 valuta_datum,      #5
                                 waehrung,          #6
                                 sollbetrag_gegenbuchung,        #7
                                 habenbetrag_gegenbuchung,       #8
                                 "",                #9
                                 fremdwaehrung,     #10
                                 fremdwaehrung_sollbetrag,  #11
                                 fremdwaehrung_habenbetrag, #12
                                 kostenstelle,       #13
                                 belegkreis,         #14
                                 belegnr,            #15
                                 ust_land,           #16
                                 "",                 #17
                                 "",                 #18
                                 ust_sondercode,     #19
                                 buchungsart,        #20
                                 abweichende_zahlungsfrist, #21
                                 abweichende_kontofrist,    #22
                                 abw_skontoprozentsatz,     #23
                                 buchungstext,  #24
                                 buchungstext2, #25
                                 uid_nummer,    #26
                                 dienstleistungsnummer, #27
                                 dienstleistungsland,   #28
                                 dienstleistungsexport, #29
                                 dms_schluessel,   #30
                                 kostentraeger,    #31
                                 fremdbelegnummer, #32
                                 wert1, #33
                                 wert2, #34
                                 mahnsperre,     #35
                                 kundendatenfeld #36
                                ]) + ";"

                lines.append(line)
                
        
        lines = "\r\n".join(lines) + "\r\n"
        charset = "cp1252"
        
        res["data"] = base64.encodestring(lines.encode(charset,"replace"))
        return res
예제 #7
0
    def _import_ofx(self, cr, uid, wizard, context=None):
        statement_obj = self.pool["account.bank.statement"]
        line_obj = self.pool["account.bank.statement.line"]

        stat_id = util.active_ids(context, "account.bank.statement")
        if not stat_id:
            return False

        stat = statement_obj.browse(cr, uid, stat_id, context=context)

        datas = wizard.ofx_datas
        if not datas:
            return False

        datab = base64.decodestring(datas)
        if not datab:
            return False

        if stat.state != "draft":
            return False

        fp = StringIO(datab)
        ofx = OfxParser.parse(fp)
        if not ofx:
            return False

        for account in ofx.accounts:
            statement = account.statement
            statement_date = util.dateToStr(statement.start_date)
            balance_end = statement.balance
            balance_start = balance_end

            lines = []
            for trans in statement.transactions:
                trans_date = datetime_field.context_timestamp(
                    cr, uid, timestamp=trans.date, context=context)

                balance_start -= trans.amount
                line = (0, 0, {
                    "sequence": len(lines) + 1,
                    "name": trans.memo,
                    "date": util.dateToStr(trans_date),
                    "ref": trans.id,
                    "amount": float(trans.amount)
                })
                lines.append(line)

            values = {}
            # change journal
            journal_id = stat.journal_id.id
            onchange_values = statement_obj.onchange_journal_id(
                cr, uid, [], journal_id).get("value")
            if onchange_values:
                values.update(onchange_values)
            # change date
            onchange_values = statement_obj.onchange_date(
                cr, uid, [], statement_date,
                values.get("company_id")).get("value")
            if onchange_values:
                values.update(onchange_values)

            values.update({
                "date": statement_date,
                "journal_id": journal_id,
                "balance_end_real": float(balance_end),
                "balance_start": float(balance_start),
                "line_ids": lines
            })

            # remove old lines
            line_ids = line_obj.search(cr, uid,
                                       [("statement_id", "=", stat.id)])
            if line_ids:
                line_obj.unlink(cr, uid, line_ids)

            # update statement
            statement_id = statement_obj.write(cr,
                                               uid, [stat.id],
                                               values,
                                               context=context)

        return True
예제 #8
0
    def action_invoice(self, cr, uid, ids, context=None):
        invoice_obj = self.pool["account.invoice"]
        invoice_line_obj = self.pool["account.invoice.line"]
        reg_obj = self.pool["academy.registration"]
        reg_inv_obj = self.pool["academy.registration.invoice"]
        fee_obj = self.pool["academy.fee"]

        wizard = self.browse(cr, uid, ids[0], context=context)
        semester = wizard.semester_id

        # registration query filter
        reg_query = []
        sel_reg_ids = util.active_ids(context, "academy.registration")
        if sel_reg_ids:
            reg_query.append(("id", "in", sel_reg_ids))

        # state filter
        reg_query.append("!")
        reg_query.append(("state", "in", ["draft", "cancel", "check"]))

        # search valid registration ids
        reg_ids = reg_obj.search(cr, uid, reg_query)

        # get semester weeks
        sem_weeks = semester.semester_weeks
        sem_start_dt = util.strToDate(semester.date_start)
        sem_end_dt = util.strToDate(semester.date_end)

        # group registrations
        for reg in reg_obj.browse(cr, uid, reg_ids, context=context):
            # check if invoice for registration exist
            reg_inv_id = reg_inv_obj.search_id(
                cr,
                uid, [("registration_id", "=", reg.id),
                      ("semester_id", "=", semester.id),
                      ("invoice_id.state", "!=", "cancel")],
                context=context)
            if reg_inv_id:
                continue

            # get invoice address
            student = reg.student_id
            partner = reg.use_invoice_address_id

            # invoice context
            inv_context = context and dict(context) or {}
            inv_context["type"] = "out_invoice"

            # get invoice or create new
            invoice_id = invoice_obj.search_id(
                cr, uid, [("state", "=", "draft"),
                          ("partner_id", "=", partner.id)])
            if not invoice_id:
                # invoice values
                inv_values = {
                    "partner_id": partner.id,
                    "name": wizard.customer_ref
                }

                inv_values.update(
                    invoice_obj.onchange_partner_id(cr,
                                                    uid, [],
                                                    "out_invoice",
                                                    partner.id,
                                                    context=context)["value"])
                invoice_id = invoice_obj.create(cr,
                                                uid,
                                                inv_values,
                                                context=context)

            # get new invoice
            invoice = invoice_obj.browse(cr, uid, invoice_id, context=context)
            # get fees
            fees = fee_obj.browse(cr,
                                  uid,
                                  fee_obj.search(cr, uid, []),
                                  context=context)

            # create line

            # add product function
            def addProduct(product,
                           uos_id=None,
                           discount=0.0,
                           discount_reason=None):
                line = {
                    "invoice_id": invoice_id,
                    "product_id": product.id,
                    "quantity": 1.0,
                    "uos_id": uos_id or product.uos_id.id
                }

                if discount:
                    line["discount"] = discount

                line.update(
                    invoice_line_obj.product_id_change(
                        cr,
                        uid, [],
                        line["product_id"],
                        line["uos_id"],
                        qty=line["quantity"],
                        type=invoice.type,
                        partner_id=invoice.partner_id.id,
                        fposition_id=invoice.fiscal_position.id,
                        company_id=invoice.company_id.id,
                        currency_id=invoice.currency_id.id,
                        context=inv_context)["value"])

                tax_ids = line.get("invoice_line_tax_id")
                if tax_ids:
                    line["invoice_line_tax_id"] = [(6, 0, tax_ids)]

                # discount reason
                if discount_reason:
                    line["name"] = _("%s - %s\n%s\n%s") % (
                        reg.name, line["name"], reg.student_id.name,
                        discount_reason)
                # or default
                else:
                    line["name"] = _("%s - %s\n%s") % (reg.name, line["name"],
                                                       reg.student_id.name)

                return invoice_line_obj.create(cr, uid, line, context=context)

            # create line

            # calc discount
            discount = 0.0
            discount_reason = None
            if reg.intership_date:
                intership_dt = util.strToDate(reg.intership_date)
                if intership_dt > sem_start_dt and intership_dt < sem_end_dt:
                    missed_duration = intership_dt - sem_start_dt
                    missed_weeks = int(missed_duration.days / 7.0)
                    if missed_weeks:
                        discount = (100.0 / sem_weeks) * missed_weeks
                        #discount_reason = _("Intership discount for %s missed weeks") % missed_weeks

            addProduct(reg.course_prod_id.product_id,
                       reg.uom_id.id,
                       discount=discount,
                       discount_reason=discount_reason)

            # add fees

            category_set = set([c.id for c in reg.location_id.category_id])

            for fee in fees:
                # check if uom is used and match
                if fee.apply_uom_id and fee.uom_id.id != reg.uom_id.id:
                    continue

                # check fee per mail
                if fee.per_mail and not reg.invoice_per_mail:
                    continue

                # check monthly invoice
                if fee.monthly and not reg.invoice_monthly:
                    continue

                # check if categories match
                if fee.location_category_ids:
                    has_category = False
                    for category in fee.location_category_ids:
                        if category.id in category_set:
                            has_category = True
                            break
                    if not has_category:
                        continue

                # check fee already paid this year
                if fee.per_year:
                    cr.execute(
                        " SELECT COUNT(l.id) FROM account_invoice_line l "
                        " INNER JOIN account_invoice inv ON inv.id = l.invoice_id AND inv.state != 'cancel' "
                        " INNER JOIN academy_registration_invoice rinv ON rinv.invoice_id = inv.id "
                        " INNER JOIN academy_semester sem ON sem.id = rinv.semester_id AND sem.year_id = %s "
                        " INNER JOIN academy_registration r ON r.id = rinv.registration_id AND r.student_id = %s "
                        " WHERE l.product_id = %s ",
                        (semester.year_id.id, student.id, fee.product_id.id))

                    rows = cr.fetchone()
                    # check if alfready invoiced this year
                    if rows and rows[0]:
                        continue

                # check for discount
                discount = 0.0
                if fee.sibling_discount:
                    parent = student.partner_id.parent_id

                    fee_query = (
                        " SELECT COUNT(l.id) FROM account_invoice_line l "
                        " INNER JOIN account_invoice inv ON inv.id = l.invoice_id AND inv.state != 'cancel' "
                        " INNER JOIN academy_registration_invoice rinv ON rinv.invoice_id = inv.id AND rinv.semester_id = %s "
                        " INNER JOIN academy_registration r ON r.id = rinv.registration_id "
                        " INNER JOIN academy_student s ON s.id = r.student_id "
                        " INNER JOIN res_partner p ON p.id = s.partner_id "
                        " WHERE l.product_id = %s "
                        "   AND l.quantity > 0 AND l.discount < 100 "
                        "   AND %s " %
                        (semester.id, fee.product_id.id, parent and
                         ("(p.parent_id = %s OR p.id = %s) " %
                          (parent.id, student.partner_id.id)) or
                         ("p.id = %s " % student.partner_id.id)))
                    cr.execute(fee_query)
                    rows = cr.fetchone()
                    # already invoiced ?
                    if rows and rows[0]:
                        discount = fee.sibling_discount

                # add fee
                addProduct(fee.product_id, discount=discount)

            # create invoice link
            reg_inv_obj.create(
                cr, uid, {
                    "registration_id": reg.id,
                    "semester_id": semester.id,
                    "invoice_id": invoice_id
                })

            # write origin
            origin = reg.name
            if invoice.origin and origin:
                origin = "%s:%s" % (invoice.origin, origin)

            # check invoice per mail
            inv_values = {"origin": origin}
            if reg.invoice_per_mail and not invoice.invoice_per_mail:
                inv_values["invoice_per_mail"] = True

            invoice_obj.write(cr, uid, invoice_id, inv_values, context=context)

            # validate invoice
            invoice_obj.button_compute(cr, uid, [invoice_id], context=context)

        return {"type": "ir.actions.act_window_close"}
예제 #9
0
    def default_get(self, cr, uid, fields_list, context=None):
        res = super(ubl_transfer_wizard,
                    self).default_get(cr, uid, fields_list, context)
        invoice_obj = self.pool.get("account.invoice")
        partner_rule_obj = self.pool.get("ubl.rule.partner")

        active_ids = util.active_ids(context, "account.invoice")
        if active_ids:
            invoice = invoice_obj.browse(cr, uid, active_ids[0], context)
        if invoice:
            # create invoice report
            report = self.pool["ir.actions.report.xml"]._lookup_report(
                cr, "account.report_invoice")
            if report:
                report_context = context.copy()
                report_context["report_title"] = invoice.number
                report.create(cr, uid, [invoice.id],
                              {"model": "account.invoice"}, report_context)

            if "invoice_id" in fields_list:
                res["invoice_id"] = invoice.id
                if "att_ids" in fields_list:
                    attach_obj = self.pool.get("ir.attachment")
                    attach_ids = attach_obj.search(
                        cr, uid, [("res_model", "=", "account.invoice"),
                                  ("res_id", "=", invoice.id)])
                    res["att_ids"] = attach_ids

            if "profile_id" in fields_list:
                ubl_profile = invoice_obj._ubl_profile(cr, uid, invoice,
                                                       context)
                if ubl_profile:
                    res["profile_id"] = ubl_profile.id
                    res["ubl_action"] = "sent"

                    no_delivery_address = False
                    partner = self._get_partner(cr,
                                                uid,
                                                invoice,
                                                context=context)
                    rule = partner_rule_obj._get_rule(cr, uid, ubl_profile.id,
                                                      partner.id)

                    invoice_partner = self._get_invoice_partner(
                        cr, uid, invoice, context=context)
                    if rule and rule.name:
                        invoice_partner = rule.name

                    if "partner_id" in fields_list:
                        if invoice_partner:
                            res["partner_id"] = invoice_partner.id
                    if "no_delivery_address" in fields_list:
                        if rule:
                            no_delivery_address = rule.no_delivery_address
                            res["no_delivery_address"] = no_delivery_address
                    if "ubl_ref" in fields_list:
                        if invoice.ubl_ref:
                            res["ubl_ref"] = invoice.ubl_ref
                        elif ubl_profile.ubl_ref:
                            res["ubl_ref"] = safe_eval(ubl_profile.ubl_ref,
                                                       locals_dict={
                                                           "partner": partner,
                                                           "invoice": invoice,
                                                           "profile":
                                                           ubl_profile
                                                       }) or invoice.number

                    if "xml_data" in fields_list:
                        res["xml_data"] = self._get_xml_data(
                            cr, uid, invoice, res.get("partner_id"),
                            res.get("ubl_ref"), no_delivery_address,
                            ubl_profile, context)

        return res
예제 #10
0
    def default_get(self, fields_list):
        res = super(wizard_export_bmd, self).default_get(fields_list)
        order_obj = self.env["pos.order"]
        line_obj = self.env["pos.order.line"]
        orders = []
        status_id = self.env["ir.model.data"].xmlid_to_res_id(
            "fpos.product_fpos_status", raise_if_not_found=True)

        session_ids = util.active_ids(self._context, "pos.session")
        if session_ids:
            orders = order_obj.search([("session_id", "in", session_ids)],
                                      order="date_order asc")
        else:
            order_ids = util.active_ids(self._context, "pos.order")
            if order_ids:
                orders = order_obj.search([("id", "in", order_ids)],
                                          order="date_order asc")

        lines = []

        # formats

        def formatFloat(inValue):
            return ("%.2f" % inValue).replace(".", ",")

        def formatSymbol(value):
            if value:
                value = value.replace("/", "")
                return value
            return None

        # write header
        line = ";".join([
            "konto", "gkto", "belegnr", "belegdat", "betrag", "mwst", "steuer",
            "steucod", "verbuchkz", "symbol", "text"
        ]) + ";"
        lines.append(line)

        #internal_account_id
        for order in orders:
            # config
            cash_statement = order.session_id.cash_statement_id
            if not cash_statement:
                raise Warning(
                    _("No cash statement for order %s found") % order.name)

            config = order.session_id.config_id
            symbol = formatSymbol(config.fpos_prefix
                                  or config.sequence_number.prefix)
            belegnr = order.name.split(config.fpos_prefix)[-1]
            belegdat = helper.strToLocalTimeFormat(self._cr,
                                                   self._uid,
                                                   order.date_order,
                                                   "%Y%m%d",
                                                   context=self._context)
            journal = cash_statement.journal_id
            debit_account = journal.default_debit_account_id
            credit_account = journal.default_credit_account_id
            internal_account = journal.internal_account_id
            if not internal_account:
                raise Warning(
                    _("No internal account defined on Journal %s for cash transfers"
                      ) % journal.name)

            name = []
            if order.pos_reference:
                name.append(order.pos_reference)
            if order.partner_id:
                name.append(order.partner_id.name)
            name = " ".join(name)

            bookings = OrderedDict()

            def post(account, betrag, mwst, steuer, text):
                # change sign
                betrag *= -1
                steuer *= -1
                key = (account.code, account.user_type.code, mwst, text)
                booking = bookings.get(key)
                if booking is None:
                    booking = (betrag, steuer)
                else:
                    booking = (booking[0] + betrag, booking[1] + steuer)
                bookings[key] = booking

            # post sale
            for line in order.lines:
                product = line.product_id
                if product.id == status_id:
                    continue

                # get tax
                tax = 0
                taxes = line_obj._get_taxes(line)
                if taxes:
                    tax = int(taxes[0].amount * 100)

                tax_amount = line.price_subtotal_incl - line.price_subtotal
                if product.income_pdt or product.expense_pdt:
                    income_account = product.property_account_income
                    if not income_account:
                        income_account = internal_account
                    post(income_account, line.price_subtotal, tax, tax_amount,
                         name)
                else:
                    income_account = product.property_account_income
                    if not income_account:
                        income_account = product.categ_id.property_account_income_categ
                    if not income_account:
                        raise Warning(
                            _("No income account for product %s defined") %
                            product.name)
                    post(income_account, line.price_subtotal, tax, tax_amount,
                         name)

            # post payment
            for payment in order.statement_ids:
                if payment.statement_id.id != cash_statement.id:
                    payment_internal_account = payment.statement_id.journal_id.internal_account_id
                    payment_account = payment_internal_account or internal_account
                    post(payment_account, -payment.amount, 0, 0,
                         payment.statement_id.journal_id.name)

            # write bookings
            for (account, user_type_code, mwst,
                 text), (betrag, steuer) in bookings.iteritems():
                # thin about changed sign
                journal_account = betrag > 0 and credit_account or debit_account
                steuer = mwst and formatFloat(steuer) or ""
                steucod = ""
                if steuer:
                    if user_type_code == "expense":
                        steucod = "00"  # VST
                    else:
                        steucod = "03"  # UST
                steuerproz = mwst and str(mwst) or ""
                line = ";".join([
                    account, journal_account.code, belegnr, belegdat,
                    formatFloat(betrag), steuerproz, steuer, steucod, "A",
                    symbol, text
                ]) + ";"
                lines.append(line)

        lines = "\r\n".join(lines) + "\r\n"
        charset = "cp1252"

        res["buerf"] = base64.encodestring(lines.encode(charset, "replace"))
        return res
예제 #11
0
 def default_get(self, fields_list):
     res = super(wizard_export_bmd, self).default_get(fields_list)
     order_obj = self.env["pos.order"]
     orders = []
     status_id = self.env["ir.model.data"].xmlid_to_res_id("fpos.product_fpos_status",raise_if_not_found=True)
     
     session_ids = util.active_ids(self._context, "pos.session")
     if session_ids:
         orders = order_obj.search([("session_id","in",session_ids)], order="date_order asc")
     else:
         order_ids = util.active_ids(self._context, "pos.order")
         if order_ids:
             orders = order_obj.search([("id","in",order_ids)], order="date_order asc")
             
     lines = []
     
     # formats
     
     def formatFloat(inValue):
         return ("%.2f" % inValue).replace(".",",")
     
     def formatSymbol(value):
         if value:
             value = value.replace("/","")
             return value
         return None 
  
     
     # write header
     line = ";".join(["konto", "gkto", "belegnr", "belegdat", "betrag", "mwst", "steuer", "steucod", "verbuchkz","symbol","text"]) + ";"
     lines.append(line)
       
     #internal_account_id
     for order in orders:      
         # config            
         cash_statement = order.session_id.cash_statement_id
         if not cash_statement:
             raise Warning(_("No cash statement for order %s found") % order.name)
         
         config = order.session_id.config_id
         symbol = formatSymbol(config.fpos_prefix or config.sequence_number.prefix)
         belegnr = order.name.split(config.fpos_prefix)[-1]
         belegdat = helper.strToLocalTimeFormat(self._cr, self._uid, order.date_order,"%Y%m%d", context=self._context)
         journal = cash_statement.journal_id
         debit_account = journal.default_debit_account_id
         credit_account = journal.default_credit_account_id
         internal_account = journal.internal_account_id
         if not internal_account:
             raise Warning(_("No internal account defined on Journal %s for cash transfers") % journal.name)
          
         name = []
         if order.pos_reference:
             name.append(order.pos_reference)
         if order.partner_id:
             name.append(order.partner_id.name)          
         name = " ".join(name)
          
         bookings = OrderedDict()
         def post(account, betrag, mwst, steuer, text):
             # change sign
             betrag *= -1
             steuer *= -1
             key = (account.code, account.user_type.code, mwst, text)
             booking = bookings.get(key)
             if booking is None:
                 booking = (betrag, steuer)
             else:
                 booking = (booking[0] + betrag, booking[1] + steuer)
             bookings[key] = booking
         
         # post sale            
         for line in order.lines:
             product = line.product_id
             if product.id == status_id:
                 continue
             
             # get tax
             tax = 0
             taxes = [t for t in product.taxes_id if not t.company_id or t.company_id == order.company_id]
             if taxes:
                 tax = int(taxes[0].amount * 100)
             
             tax_amount = line.price_subtotal_incl - line.price_subtotal
             if product.income_pdt or product.expense_pdt:
                 income_account = product.property_account_income
                 if not income_account:
                     income_account = internal_account
                 post(income_account, line.price_subtotal, tax, tax_amount, name)
             else:
                 income_account = product.property_account_income
                 if not income_account:
                     income_account = product.categ_id.property_account_income_categ
                 if not income_account:
                     raise Warning(_("No income account for product %s defined") % product.name)
                 post(income_account, line.price_subtotal, tax, tax_amount, name)
     
         # post payment
         for payment in order.statement_ids:                
             if payment.statement_id.id != cash_statement.id:
                 payment_internal_account = payment.statement_id.journal_id.internal_account_id
                 payment_account = payment_internal_account or internal_account
                 post(payment_account, -payment.amount, 0, 0, payment.statement_id.journal_id.name)
                 
         # write bookings            
         for (account, user_type_code, mwst, text), (betrag, steuer) in bookings.iteritems():                
             # thin about changed sign                
             journal_account = betrag > 0 and credit_account or debit_account                
             steuer = mwst and formatFloat(steuer) or ""
             steucod = ""
             if steuer:
                 if user_type_code == "expense":
                     steucod = "00" # VST
                 else:
                     steucod = "03" # UST
             steuerproz = mwst and str(mwst) or ""
             line = ";".join([account, journal_account.code, belegnr, belegdat, formatFloat(betrag), steuerproz, steuer, steucod, "A", symbol, text]) + ";"
             lines.append(line)
     
     lines = "\r\n".join(lines) + "\r\n"
     charset = "cp1252"
     
     res["buerf"] = base64.encodestring(lines.encode(charset,"replace"))
     return res