Search in sources :

Example 51 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.

the class PurchaseOrderLineController method supplierPartnerDomain.

/**
 * Called on supplier partner select. Set the domain for the field supplierPartner
 *
 * @param request
 * @param response
 */
public void supplierPartnerDomain(ActionRequest request, ActionResponse response) {
    PurchaseOrderLine purchaseOrderLine = request.getContext().asType(PurchaseOrderLine.class);
    PurchaseOrder purchaseOrder = request.getContext().getParent().asType(PurchaseOrder.class);
    if (purchaseOrder.getId() != null) {
        purchaseOrder = purchaseOrderLine.getPurchaseOrder();
    }
    Company company = purchaseOrder.getCompany();
    String domain = "";
    if (Beans.get(AppPurchaseService.class).getAppPurchase().getManageSupplierCatalog() && purchaseOrderLine.getProduct() != null && !purchaseOrderLine.getProduct().getSupplierCatalogList().isEmpty()) {
        domain += "self.id != " + company.getPartner().getId() + " AND self.id IN " + purchaseOrderLine.getProduct().getSupplierCatalogList().stream().map(s -> s.getSupplierPartner().getId()).collect(Collectors.toList()).toString().replace('[', '(').replace(']', ')');
        String blockedPartnerQuery = Beans.get(BlockingService.class).listOfBlockedPartner(company, BlockingRepository.PURCHASE_BLOCKING);
        if (!Strings.isNullOrEmpty(blockedPartnerQuery)) {
            domain += String.format(" AND self.id NOT in (%s)", blockedPartnerQuery);
        }
    } else {
        domain += "self.id = 0";
    }
    domain += " AND " + company.getId() + " in (SELECT id FROM self.companySet)";
    response.setAttr("supplierPartner", "domain", domain);
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) Company(com.axelor.apps.base.db.Company) BlockingService(com.axelor.apps.base.service.BlockingService) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder)

Example 52 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.

the class PurchaseOrderLineController method getPurchaseOrder.

public PurchaseOrder getPurchaseOrder(Context context) {
    Context parentContext = context.getParent();
    PurchaseOrder purchaseOrder = null;
    if (parentContext != null && parentContext.getContextClass() == PurchaseOrder.class) {
        purchaseOrder = parentContext.asType(PurchaseOrder.class);
        if (!parentContext.getContextClass().toString().equals(PurchaseOrder.class.toString())) {
            PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
            purchaseOrder = purchaseOrderLine.getPurchaseOrder();
        }
    } else {
        PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
        purchaseOrder = purchaseOrderLine.getPurchaseOrder();
    }
    return purchaseOrder;
}
Also used : Context(com.axelor.rpc.Context) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder)

Example 53 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.

the class PurchaseOrderLineController method getTaxEquiv.

public void getTaxEquiv(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
    PurchaseOrder purchaseOrder = getPurchaseOrder(context);
    response.setValue("taxEquiv", null);
    if (purchaseOrder == null || purchaseOrderLine == null || purchaseOrder.getSupplierPartner() == null || purchaseOrderLine.getTaxLine() == null)
        return;
    response.setValue("taxEquiv", Beans.get(FiscalPositionService.class).getTaxEquiv(purchaseOrder.getSupplierPartner().getFiscalPosition(), purchaseOrderLine.getTaxLine().getTax()));
}
Also used : Context(com.axelor.rpc.Context) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder)

Example 54 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.

the class PurchaseOrderLineTaxService method createsPurchaseOrderLineTax.

/**
 * Créer les lignes de TVA de la commande. La création des lignes de TVA se basent sur les lignes
 * de commande.
 *
 * @param purchaseOrder La commande.
 * @param purchaseOrderLineList Les lignes de commandes.
 * @return La liste des lignes de TVA de la commande.
 */
public List<PurchaseOrderLineTax> createsPurchaseOrderLineTax(PurchaseOrder purchaseOrder, List<PurchaseOrderLine> purchaseOrderLineList) {
    List<PurchaseOrderLineTax> purchaseOrderLineTaxList = new ArrayList<PurchaseOrderLineTax>();
    Map<TaxLine, PurchaseOrderLineTax> map = new HashMap<TaxLine, PurchaseOrderLineTax>();
    if (purchaseOrderLineList != null && !purchaseOrderLineList.isEmpty()) {
        LOG.debug("Création des lignes de tva pour les lignes de commande.");
        for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
            TaxLine taxLine = purchaseOrderLine.getTaxLine();
            TaxEquiv taxEquiv = purchaseOrderLine.getTaxEquiv();
            TaxLine taxLineRC = (taxEquiv != null && taxEquiv.getReverseCharge() && taxEquiv.getReverseChargeTax() != null) ? taxEquiv.getReverseChargeTax().getActiveTaxLine() : null;
            if (taxLine != null) {
                LOG.debug("TVA {}", taxLine);
                if (map.containsKey(taxLine)) {
                    PurchaseOrderLineTax purchaseOrderLineVat = map.get(taxLine);
                    purchaseOrderLineVat.setExTaxBase(purchaseOrderLineVat.getExTaxBase().add(purchaseOrderLine.getExTaxTotal()));
                    purchaseOrderLineVat.setReverseCharged(false);
                } else {
                    PurchaseOrderLineTax purchaseOrderLineTax = new PurchaseOrderLineTax();
                    purchaseOrderLineTax.setPurchaseOrder(purchaseOrder);
                    purchaseOrderLineTax.setExTaxBase(purchaseOrderLine.getExTaxTotal());
                    purchaseOrderLineTax.setReverseCharged(false);
                    purchaseOrderLineTax.setTaxLine(taxLine);
                    map.put(taxLine, purchaseOrderLineTax);
                }
            }
            if (taxLineRC != null) {
                LOG.debug("TVA {}", taxLineRC);
                if (map.containsKey(taxLineRC)) {
                    PurchaseOrderLineTax purchaseOrderLineRC = map.get(taxEquiv.getReverseChargeTax().getActiveTaxLine());
                    purchaseOrderLineRC.setExTaxBase(purchaseOrderLineRC.getExTaxBase().add(purchaseOrderLine.getExTaxTotal()));
                    purchaseOrderLineRC.setReverseCharged(true);
                } else {
                    PurchaseOrderLineTax purchaseOrderLineTaxRC = new PurchaseOrderLineTax();
                    purchaseOrderLineTaxRC.setPurchaseOrder(purchaseOrder);
                    purchaseOrderLineTaxRC.setExTaxBase(purchaseOrderLine.getExTaxTotal());
                    purchaseOrderLineTaxRC.setReverseCharged(true);
                    purchaseOrderLineTaxRC.setTaxLine(taxLineRC);
                    map.put(taxLineRC, purchaseOrderLineTaxRC);
                }
            }
        }
    }
    for (PurchaseOrderLineTax purchaseOrderLineTax : map.values()) {
        // Dans la devise de la commande
        BigDecimal exTaxBase = (purchaseOrderLineTax.getReverseCharged()) ? purchaseOrderLineTax.getExTaxBase().negate() : purchaseOrderLineTax.getExTaxBase();
        BigDecimal taxTotal = BigDecimal.ZERO;
        if (purchaseOrderLineTax.getTaxLine() != null)
            taxTotal = purchaseOrderToolService.computeAmount(exTaxBase, purchaseOrderLineTax.getTaxLine().getValue());
        purchaseOrderLineTax.setTaxTotal(taxTotal);
        purchaseOrderLineTax.setInTaxTotal(purchaseOrderLineTax.getExTaxBase().add(taxTotal));
        purchaseOrderLineTaxList.add(purchaseOrderLineTax);
        LOG.debug("Ligne de TVA : Total TVA => {}, Total HT => {}", new Object[] { purchaseOrderLineTax.getTaxTotal(), purchaseOrderLineTax.getInTaxTotal() });
    }
    return purchaseOrderLineTaxList;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TaxEquiv(com.axelor.apps.account.db.TaxEquiv) BigDecimal(java.math.BigDecimal) PurchaseOrderLineTax(com.axelor.apps.purchase.db.PurchaseOrderLineTax) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 55 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.

the class PurchaseOrderServiceImpl method _computePurchaseOrderLines.

@Override
public PurchaseOrder _computePurchaseOrderLines(PurchaseOrder purchaseOrder) throws AxelorException {
    if (purchaseOrder.getPurchaseOrderLineList() != null) {
        PurchaseOrderLineService purchaseOrderLineService = Beans.get(PurchaseOrderLineService.class);
        for (PurchaseOrderLine purchaseOrderLine : purchaseOrder.getPurchaseOrderLineList()) {
            purchaseOrderLine.setExTaxTotal(purchaseOrderLineService.computePurchaseOrderLine(purchaseOrderLine));
            purchaseOrderLine.setCompanyExTaxTotal(purchaseOrderLineService.getCompanyExTaxTotal(purchaseOrderLine.getExTaxTotal(), purchaseOrder));
        }
    }
    return purchaseOrder;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine)

Aggregations

PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)76 BigDecimal (java.math.BigDecimal)28 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)26 Transactional (com.google.inject.persist.Transactional)18 Product (com.axelor.apps.base.db.Product)14 ArrayList (java.util.ArrayList)13 AxelorException (com.axelor.exception.AxelorException)11 Context (com.axelor.rpc.Context)10 Company (com.axelor.apps.base.db.Company)9 Unit (com.axelor.apps.base.db.Unit)9 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)9 PurchaseOrderLineService (com.axelor.apps.purchase.service.PurchaseOrderLineService)8 LocalDate (java.time.LocalDate)8 Partner (com.axelor.apps.base.db.Partner)7 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)7 HashMap (java.util.HashMap)7 BudgetDistribution (com.axelor.apps.account.db.BudgetDistribution)5 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)5 TaxLine (com.axelor.apps.account.db.TaxLine)5 List (java.util.List)5